artifact:install pushes the super-pom instead of the POM I define

别说谁变了你拦得住时间么 提交于 2019-12-21 11:00:13

问题


I have a POM defined in the Ant file, the build works correctly, pulling the correct artifacts from the Repository, however, the artifact:install tasks pushes to 'super-pom' instead of the pom I specify

I use the following POM file

<project name="my-proj" default="build" 
         xmlns:artifact="antlib:org.apache.maven.artifact.ant">

  <!-- Define the Maven tasks -->
  <path id="mvn.classpath" 
        path="${env.MAVEN_HOME}/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="mvn.classpath" />


  <target name="set-deps">
    <artifact:pom id="jar.pom" packaging="jar"
                  groupId="com.me" artifactId="my-proj" 
                  version="1.0-SNAPSHOT">
      <dependency groupId="commons-logging" 
                  artifactId="commons-logging" 
                  version="1.1.1"/>
    </artifact:pom>

    <artifact:dependencies filesetId="project.jar.files" 
          pomRefId="jar.pom"/>
  </target>

  <target name="compile" depends="set-deps">
    <mkdir dir="${basedir}/output/casses"/>
    <javac srcdir="${basedir}/src" 
           destdir="${basedir}/output/classes" 
           classpathref="project.jar.files" />
  </target>

  <target name="build" depends="compile">
    <jar destfile="output/${project.name}.jar" 
         basedir="${basedir}/output/classes"/>
  </target>

  <target name="install" depends="build">
    <echo message="Installing JAR file - ${project.name}.jar"/>
    <echo message=" groupId - ${jar.pom.groupId}"/>
    <echo message="artifactId - ${jar.pom.artifactId}"/>
    <echo message=" version - ${jar.pom.version}"/>
    <artifact:install file="${basedir}/output/${project.name}.jar" 
          pomRefId="jar.pom"/>
  </target>
</project>

Calling ant build will build the JAR file correctly, so the POM is being set up correctly by the Ant script (at least from a dependency point of view).

However, calling ant install results in the JAR being installed on the local repository as super-pom version 1.0. installing a second time fails as a full version (1.0, no SNAPSHOT) already exists on the repository and only SNAPSHOT versions can be overwritten.

I've set the groupId/artifactId/version on the POM. How come they are not being picked up? I've tried setting these again on the install task (thinking maybe there were undocumented attributes for the task), but this task does not accept these attributes.

In fact, the correct values will get displayed before the install, so the POM knows it's groupId/artifactId/version, but still fails the install using these settings.

BTW, if it's any help, I'm using the 2.1.1 maven-ant-tasks JAR file, but the Maven version I have installed is 3.0.2 (not sure whether the tasks make external calls to the Maven Jars or if the functionality is internal to the ant task Jar).

PS. I've tried placing the dependencies in an external POM file and this seems to work, the pom.xml contains nothing but the dependencies and the groupId/artifactId/version (same as the in-memory pom defined above), the artifact:pom changes to:

<artifact:pom id="jar.pom" file="ant-pom.xml"/>

Nothing else changes, but ant install now works correctly. Is this a bug in the maven-ant-tasks or is there something I'm missing?

Where I'm working now use Ant, and I want to avoid giving more files to be managed as part of the build process. If I need to I will, but I'd rather avoid it!


回答1:


OK, in lieu of waiting for a fix for this issue, I went with a work-around. I write out the POM in the install, then use the disk-based POM for the install:

...
<target name="install" ...
  ...
  <artifact:writepom pomRefId="jar.pom" file="${basedir}/output/${project.name}-pom.xml" />
  <artifact:pom id="disk-based.pom" file="${basedir}/output/${project.name}-pom.xml" />

  <artifact:install file="${basedir}/output/${project.name}.jar" 
      pomRefId="disk-based.pom"/>
</target>
...

Hope this helps.



来源:https://stackoverflow.com/questions/4887018/artifactinstall-pushes-the-super-pom-instead-of-the-pom-i-define

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!