tags:

views:

36

answers:

1

I've been trying to use writepom using this http://maven.apache.org/ant-tasks/examples/write-pom.html as a reference and have been having problems. I'm essentially just trying to test whether it will actually work so the POM file is quite bare. See below.

<project name="CreatePOMStructure" basedir="./test" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
 <description>
  Test Script
 </description>

 <path id="maven-ant-tasks.classpath" path="/usr/local/apache-ant-1.8.1/lib/maven-ant-tasks-2.1.1.jar" />
 <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
            uri="antlib:org.apache.maven.artifact.ant"
            classpathref="maven-ant-tasks.classpath" />

 <artifact:pom id="maven-pom" groupId="com.cgi.wealth" artifactId="maven-pom-setup" version="1.0" name="maven-setup">
  <license name="apache" url="http://www.apache.org"/&gt;
     <dependency groupId="junit" artifactId="junit" version="4.1" scope="test"/>
     <dependency groupId="org.codehaus.plexus" artifactId="plexus-utils" version="1.5.5"/>
 </artifact:pom>

 <artifact:writepom pomRefId="mypom1" file="mypom1.xml"/>

</project>

I get this error when I try to run ant

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.0:run (compile) on project maven-setup: Error executing ant tasks: The following error occurred while executing this line: /maven-setup/scripts/build.xml:11: java.lang.NoSuchMethodError: org.apache.maven.settings.RuntimeInfo.(Lorg/apache/maven/settings/Settings;)V -> [Help 1]

I'm not sure if it's relevant, but before I added the typedef I was getting this error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.0:run (compile) on project maven-setup: Error executing ant tasks: The following error occurred while executing this line:/maven-setup/scripts/build.xml:9: Could not create task or type of type: antlib:org.apache.maven.artifact.ant:pom.

Ant could not find the task or a class this task relies upon.

Sorry for the most likely basic question, but I can't seem to fix this myself.

[EDIT]

Here's the pom.xml file which I use to run the ant build.

    <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"&gt;
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.cgi.wealth</groupId>
  <artifactId>maven-setup</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>

                <version>1.0</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>generate-sources</phase>
                        <configuration>            
                            <tasks>
                                <ant antfile="${basedir}/scripts/build.xml" />
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-ant-tasks</artifactId>
            <version>2.1.1</version>
        </dependency>
    </dependencies>    
</project>

The problem with the project only exists when running the maven task "mvn generate-sources" (see pom.xml above). When I just run "ant" it builds successfully. Any insight is greatly appreciated.

+1  A: 

This script runs fine, provided you've put maven-ant-tasks-2.1.1.jar into the same directory where your build.xml lives.
The errors you are encountering tell me that the path may be incorrect.

Also, it's better not to set basedir attribute of your project and use a default ( current directory of the build.xml )

Last, but not least, artifact:writepom pomRefId should match the id of artifact:pom.

Below is the script:

<project
  name="CreatePOMStructure"
  default="default"
  xmlns:artifact="antlib:org.apache.maven.artifact.ant"
>
   <path id="maven-ant-tasks.classpath" path="maven-ant-tasks-2.1.1.jar" />

   <typedef
     resource="org/apache/maven/artifact/ant/antlib.xml"
     uri="antlib:org.apache.maven.artifact.ant"
     classpathref="maven-ant-tasks.classpath"
   />

   <target name="default">
     <artifact:pom id="maven-pom"
       groupId="com.cgi.wealth"
       artifactId="maven-pom-setup"
       version="1.0"
       name="maven-setup"
     >
       <license name="apache" url="http://www.apache.org"/&gt;
       <dependency
         groupId="junit"
         artifactId="junit"
         version="4.1"
         scope="test"
       />
       <dependency
         groupId="org.codehaus.plexus"
         artifactId="plexus-utils"
         version="1.5.5"
       />
     </artifact:pom>

     <artifact:writepom pomRefId="maven-pom" file="mypom1.xml"/>
   </target>

</project>
Alexander Pogrebnyak
Unfortunately I still seem to get the same errors when I try to change it as you suggested. If I move the jar file to the same directory as the build.xml file (and change the path to it in the script as you did) I get the first error that I had about not being able to create the task. Any other thoughts?
mdangelo
Sorry for the confusion, I was running the script using maven (see pom.xml in original question), but running ant directly now works. Do you have any ideas on how I could get this to work using the maven pom.xml? I have added the pom.xml to my original question. In any case, your help has been greatly appreciated :)
mdangelo
@mdangelo. Read this article about referencing class path in antrun plugin -> http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html. In your case I think the classpath in `typedef` should be `${org.apache.maven:maven-ant-tasks:jar}`
Alexander Pogrebnyak