Maven Ant Tasks
  1. Maven Ant Tasks
  2. MANTTASKS-19

M2/ANT : Weird ClassCastException in <m:pom> in macrodef when calling Beanshell scripting.

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      - ANT 1.6.5 (with bsh-2.0b4.jar in ANT_HOME/lib)
      - JDK 1.5
    • Number of attachments :
      2

      Description

      Hi,

      In ANT, sometimes more than one artifact is generated from the same
      build file (e.g. myapp.jar, myapp-client.jar, myapp-with-deps.jar).

      If using the M2 plugin for ANT (currently 2.0.4), this would mean
      we would need three POM's for the above 3 artifacts. However, in the
      above case the 3 POM's would be almost identical.

      So I have taken the following approach in order to have only one generic
      POM:

      pom.xml (with ANT tokens TOKEN...):

      <project xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>be.steria.test</groupId>
      <artifactId>TOKEN_ARTIFACTID</artifactId>
      <packaging>TOKEN_PACKAGING</packaging>
      <version>1.5-SNAPSHOT</version>
      <description>Test artifact</description>
      <dependencies>
      <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.9</version>
      <scope>compile</scope>
      </dependency>
      <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
      </dependency>
      </dependencies>
      <distributionManagement>
      <repository>
      <id>repo_dev</id>
      <url>scp://localhost/m2demo/repo_dev</url>
      </repository>
      </distributionManagement>
      </project>

      build.xml:

      <project name="example-ant-using-m2-plugin" default="m2init"
      xmlns:m="antlib:org.apache.maven.artifact.ant">

      <macrodef name="create-pom">
      <attribute name="pomRefId"/>
      <attribute name="artifactId"/>
      <attribute name="packaging" default="jar"/>
      <sequential>
      <!-- IMPORTANT : derived POM files must be generated in the same
      folder as pom.xml, otherwise the paths, ... will be incorrect -->
      <copy file="pom.xml" filtering="true"
      toFile="pom-@

      {pomRefId}.derived.xml">
      <filterchain>
      <tokenfilter>
      <replacestring from="TOKEN_ARTIFACTID"
      to="@{artifactId}"/>
      <replacestring from="TOKEN_PACKAGING"
      to="@{packaging}"/>
      </tokenfilter>
      </filterchain>
      </copy>
      <m:pom id="@{pomRefId}

      " file="pom-@

      {pomRefId}

      .derived.xml"/>
      </sequential>
      </macrodef>

      <target name="m2init">

      <m:pom id="M2POM" file="pom.xml"/>

      <!-- causes ClassCastException in macrodef 'create-pom' -->
      <!-script language="beanshell"/->

      <!-- create POM's on-the-fly (one for each artifact) -->
      <create-pom pomRefId="M2POM_MYAPP" artifactId="myapp"/>
      <create-pom pomRefId="M2POM_MYAPP_CLIENT" artifactId="myapp-client"/>
      <create-pom pomRefId="M2POM_MYAPP_WITH_DEPS" artifactId="myapp-with-deps"/>

      </target>

      <target name="package" depends="m2init">
      <!-- ... generate artifacts (pure ANT) ... -->
      </target>

      <target name="install" depends="package">
      <m:install file="myapp.jar"
      pomRefId="M2POM_MYAPP"/>
      <m:install file="myapp-client.jar"
      pomRefId="M2POM_MYAPP_CLIENT"/>
      <m:install file="myapp-with-deps.jar"
      pomRefId="M2POM_MYAPP_WITH_DEPS"/>
      </target>

      <target name="deploy">
      <m:deploy file="myapp.jar"
      pomRefId="M2POM_MYAPP"/>
      <m:deploy file="myapp-client.jar"
      pomRefId="M2POM_MYAPP_CLIENT"/>
      <m:deploy file="myapp-with-deps.jar"
      pomRefId="M2POM_MYAPP_WITH_DEPS"/>
      </target>

      </project>

      Now if I execute the above, everything works fine, but if I add <script
      language="beanshell"/> in the target 'm2init', then the following error
      is generated on the first <create-pom> call:

      "java.lang.ClassCastException: org.apache.maven.artifact.ant.Pom"

      Regards,
      Davy Toch

      1. build.xml
        2 kB
        Davy Toch
      2. pom.xml
        1.0 kB
        Davy Toch

        Activity

        Hide
        Antoine Levy-Lambert added a comment -

        Hello Davy,

        this problem might be due to Ant, not to Maven.

        It looks like it Ant's bug 40238 which is fixed in Ant 1.7.

        You can download Ant 1.7.0Beta2 from ant.apache.org to check whether this solves your issue.

        Regards,

        Antoine

        Show
        Antoine Levy-Lambert added a comment - Hello Davy, this problem might be due to Ant, not to Maven. It looks like it Ant's bug 40238 which is fixed in Ant 1.7. You can download Ant 1.7.0Beta2 from ant.apache.org to check whether this solves your issue. Regards, Antoine
        Hide
        Davy Toch added a comment -

        Tried it with ANT 1.7.0Beta1 but unfortunately same problem. Will try it with 1.7.0Beta2 once the Apache site is up again.

        Show
        Davy Toch added a comment - Tried it with ANT 1.7.0Beta1 but unfortunately same problem. Will try it with 1.7.0Beta2 once the Apache site is up again.
        Hide
        Davy Toch added a comment -

        Also tried it with ANT 1.7.0Beta2 but unfortunately the same problem arises.

        Show
        Davy Toch added a comment - Also tried it with ANT 1.7.0Beta2 but unfortunately the same problem arises.
        Hide
        Antoine Levy-Lambert added a comment -

        Hello Davy,

        can you start ant with -verbose or -debug to get a stack trace.

        If the stack trace leads you to believe that it is an ant bug (could be) then you can cross post this issue in bugzilla.

        Mention it here so that the Maven developers know that this is followed up on the Ant side.

        Regards,

        Antoine

        Show
        Antoine Levy-Lambert added a comment - Hello Davy, can you start ant with -verbose or -debug to get a stack trace. If the stack trace leads you to believe that it is an ant bug (could be) then you can cross post this issue in bugzilla. Mention it here so that the Maven developers know that this is followed up on the Ant side. Regards, Antoine
        Hide
        Davy Toch added a comment -

        Apparently the problem is known and can be solved by a hack using
        the attribute setbeans="false" on <script> that is only available in
        ANT 1.7.0+, so instead of:

        <script language="beanshell"/>

        you must set :

        <script language="beanshell" setbeans="false"/>

        The problem is documented here :

        http://issues.apache.org/bugzilla/show_bug.cgi?id=37688

        However, as indicated by the comment:

        http://issues.apache.org/bugzilla/show_bug.cgi?id=37688#c4

        a newer version of ANT 1.7.0 would normally not need the attribute
        setbeans="false" to avoid the problem (I tested it with ANT 1.7.0beta2).

        I'll leave this open, just in case somebody of the M2 team would like
        to add a small comment on the M2 site regarding this problem.

        Show
        Davy Toch added a comment - Apparently the problem is known and can be solved by a hack using the attribute setbeans="false" on <script> that is only available in ANT 1.7.0+, so instead of: <script language="beanshell"/> you must set : <script language="beanshell" setbeans="false"/> The problem is documented here : http://issues.apache.org/bugzilla/show_bug.cgi?id=37688 However, as indicated by the comment: http://issues.apache.org/bugzilla/show_bug.cgi?id=37688#c4 a newer version of ANT 1.7.0 would normally not need the attribute setbeans="false" to avoid the problem (I tested it with ANT 1.7.0beta2). I'll leave this open, just in case somebody of the M2 team would like to add a small comment on the M2 site regarding this problem.
        Hide
        Davy Toch added a comment -

        The problem seems to be fixed since ANT 1.7.0beta3.

        Show
        Davy Toch added a comment - The problem seems to be fixed since ANT 1.7.0beta3.
        Hide
        Jason van Zyl added a comment -

        Reported as being fixed.

        Show
        Jason van Zyl added a comment - Reported as being fixed.

          People

          • Assignee:
            Unassigned
            Reporter:
            Davy Toch
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: