Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workaround for nested subant property override behaviour (since 1.8.0)

Tags:

ant

I am using apache ant in the following way:

I have projects P1, P2, P3. Some of those projects have modules, let say P2 has M1, M2, etc. All projects have their own ant build script, and all of them have to implement set of predefined targets (build, dist, etc), the scripts expect some properties to be defined when called. let say (build.dir.base)

The modules follow similar structure, so every modules, has its own build file that implements the predefined set of targets, and expects some properties to be set. (let say build.dir.base - same as for the projects)

I also have a global ant script that builds all the projects (or subset)

In code that would look like:

build-all.xml:

<project name="x">
    <property name="build.dir.base" location="system.build.base" />
    <target name="build">
        <echo message="build.dir.base as defined for build-all.xml=${build.dir.base}" />
        <subant antfile="build.xml" target="build" inheritAll="false" inheritRefs="false">
            <dirset dir="${system.base}" includes="${project-list}" />
            <property name="build.dir.base" location="${build.dir.base}" />
        </subant>
    </target>
</project>

build.xml (one for each project with modules, no subant if project does not have modules):

<project name="y">
    <property name="build.dir" location="${basedir}/build" />
    <target name="build">
        <echo message="build.dir.base as defined for project=${build.dir.base}" />
        <subant antfile="build.xml" target="build" inheritAll="false" inheritRefs="false">
            <dirset dir="project.base" includes="${module-list}" />
            <property name="build.dir.base" location="${build.dir.base}/${name}" />
        </subant>
    </target>
</project>

And for the projects that have modules: build.xml (for a module):

<project name="z">
    <property name="build.dir.base" location="build.dir.base" />
        <target name="build">
            <echo message="build.dir.base as defined for module=${build.dir.base}" />
        </target>
</project>

This structure allows projects to be built independently, also modules can be build independently or the whole system can be built using the build-all.xml. Also, the final product has the folowing structure:

  • ${system.build.base}/P1,
  • ${system.build.base}/P2/M1
  • ${system.build.base}/P2/M2

etc

However, since ant >= 1.8.0 this is not possible any more. The reason is that <property name="build.dir.base" location="${basedir}/build" /> in build-all.xml takes precedence over <property name="build.dir.base" location="${build.dir.base}/${name}" /> in build.xml (build for projects). So, the destination of the project "submodules" is in ${system.build.base}/M1 instead of ${system.build.base}/P2/M1

This is explained Properties defined on the command line cannot be overridden by nested elements. Since Ant 1.8.0. the same is true for nested structures of tasks: if a build file A invokes B via an task setting a property with a nested element and B contains an tasks invoking C, C will see the value set in A, even if B used a nested element as well.

There is no way to override a property for subant if some of the parents also defined that property. This is severe, since the build should be aware for properties that the parent used for some unrelated reason.

Is there workaround for this incompatible change in behavior? Since, my build system heavily relies on the fact that <subant inheritAll="false" inheritRefs="false"> will do the exec without polluting the sub-builds.

like image 406
Op De Cirkel Avatar asked Nov 04 '22 05:11

Op De Cirkel


1 Answers

https://issues.apache.org/bugzilla/show_bug.cgi?id=49891 also seems related to this question.

After trying out many different things (including the technique of filtering out the unwanted property then resetting it), I have concluded that it is impossible to override command-line properties in a subant task.

like image 118
Noel Yap Avatar answered Dec 04 '22 05:12

Noel Yap