0

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?

Blessed Geek
  • 21,058
  • 23
  • 106
  • 176
  • Reference - http://maven.apache.org/ant-tasks/examples/pom.html – Blessed Geek Sep 28 '12 at 20:50
  • 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 Sep 28 '12 at 20:53
  • 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 Sep 28 '12 at 21:01
  • 2
    Have you tried debugging the fileset? http://stackoverflow.com/questions/3934309/echoing-out-ant-fileset-to-screen-for-debugging – oers Sep 28 '12 at 21:57
  • 2
    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 Sep 28 '12 at 22:55

1 Answers1

1

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.

Blessed Geek
  • 21,058
  • 23
  • 106
  • 176