0
votes

My project was constructed using Maven. I was happily building it with Maven. Now, I need to build it with Ant (which I wish I needn't!!!). I wish to use existing maven dependencies - i.e., wish to retain the pom for dependency management.

So, I wrote this task:

<target name="java.compile">
  <artifact:pom id="mypom" file="pom.xml" />
  <artifact:dependencies filesetId="mypomdeps" pomRefId="mypom" />

  <mkdir dir="build/classes" />

  <javac
    srcdir="${src.java.dir}"
    destdir="build/classes"
    includeantruntime="no">

    <classpath>
      <fileset refid="mypomdeps"/>
    </classpath>

  </javac>
</target>

However, the ant compilation output complains the libraries(in the jars) pointed to by mypomdeps are missing.

What are the reasons that javac was unable to see the classpath that I intended?

Am I using the filesetId generated by artifact:dependencies correctly?

My ant project defn:
I placed maven-ant-tasks-2.1.3.jar in the project basedir.

<project name="why-does-the-sun-go-on-shining"
  default="java.compile"
  xmlns:artifact="antlib:org.apache.maven.artifact.ant">

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

Further Clarification

The gist of the question is ... how to use my pom dependencies in my Ant javac task?

1
I'd like to know why you have to use ant since maven was working all right... Usually the companies do the inverse way (from bash to ant and then to maven).Gilberto Torrezan
Gilberto, please don't ask me why people wish to vote for Romney when Obama is doing so well. Let's not compel me to justify for reasons I don't agree with.Blessed Geek
Have you tried debugging the fileset? stackoverflow.com/questions/3934309/…oers
Oers, you hit the nail. My ant target was done correctly - however, my dependencies were system scope and the ant artifact:dependency task would not resolve system scope.Blessed Geek

1 Answers

1
votes

Would like to answer my own question to say that

My ant targets and definition were correct. The refid to artefact dependencies are properly referenced.

However, there were some system scope dependencies defined in the pom.

antlib:org.apache.maven.artifact.ant would not resolve system scoped transitive dependencies. e.g.,

<dependencies>
  <dependency>
    <groupId>sun.jdk</groupId>
    <artifactId>tools</artifactId>
    <version>LATEST</version>
    <scope>system</scope>
    <systemPath>${java.home}/../lib/tools.jar</systemPath>
  </dependency>
</dependencies>

Thanks to Oers' getting me to debug the ant script by issuing echo elements.