开发者

How to use artifact:writepom and artifact:pom?

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"/>
     <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">
  <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.


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"/>
       <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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜