tags:

views:

42

answers:

1

Hi,

I'm using Ant to build a custom jar library, which then I'm using in Maven as dependency.

<dependency>
    <groupId>test-lib</groupId>
    <artifactId>test-lib</artifactId>
    <version>1.0.0system</scope>
    <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/test-lib-1.0.0.jar</systemPath>
</dependency>

So, basically what I do now is:

1) run ant to build custom library (test-lib-1.0.0.jar)
2) run: mvn compile, to compile my project using custom library among others.

Is there an option for me to do all this (packaing custom jar & compiling project) from Maven? I've found maven run plugin, and here are my settings:

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.4
                <executions>
                    <execution>
                        <phase>?????what to put here?????/phase>
                        <configuration>
                            <tasks>
                                <ant antfile="${basedir}/build.xml">
                                    <target name="prepare-test-lib" />
                                </ant>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

But, when running: 'mvn compile' it complains about missing artifact: test-lib-1.0.0.jar. I've used compile, generate-resouces,... in <phase/> tag, but nothing seems to work.

Is it possible to solve this somehow using this plugin?

+1  A: 

When using the Maven Antrun Plugin, Maven tries to resolve the dependencies to build ClassPaths for the AntRun invocation and you thus face a chicken and egg problem : you can't declare a dependency that will be created during AntRun execution that requires this dependency to run. This can't work.

My recommendation would be to mavenize your test-lib, to include it in your project build and to declare a regular dependency on it. In other words, what I mean is moving from Ant to Maven to build your test-lib and setting up a multi-modules project. To illustrate things more "visually", something like this:

my-project
|-- my-module
|   |-- src
|   |   `-- main
|   |       `-- java
|   `-- pom.xml
|-- test-lib
|   |-- src
|   |   `-- main
|   |       `-- java
|   `-- pom.xml
`-- pom.xml

Where my-project/pom.xml is an aggregating pom with a <packaging>pom</packaging> and list the modules under a <modules> element:

<modules>
  <module>my-module</module>
  <module>test-lib</module>
</modules>

And where my-module/pom.xml declares a dependency on the test-lib artifact:

<dependency>
  <groupId>your.group.id</groupId>
  <artifactId>test-lib</artifactId>
  <version>1.0-SNAPSHOT</version>
</dependency>

I'm just giving a very high-level overview here, you need to read the documentation a bit for the details, I can't cover everything. Start with the first book from Sonatype (link below).

But that would be the right way to go (and you should just not (ab)use system scoped dependencies).

References

Pascal Thivent
Thanx for your answer Pascal! Ok, so basically I need to do things differently. But what do you mean by 'mavenize your test-lib'? Do you mean that I should install test-lib on my local maven repository? I tried to avoid this, since test-lib is quite small library, implementing API used in my project, and I want be using it in other projects, for sure.
Igor Bolic
@Igor No, I don't mean just installing the test-lib in your local repository, I mean creating a specific maven module and putting the test-lib sources in it (i.e. moving from ant to maven to build it) so that you can include its packaging as part of your build if required (it's IMHO not a problem that it's a small lib, au contraire).
Pascal Thivent
@Pasacal How can I include test-lib in my project build, and after that to declare standard dependency on it? I would really appreciate if you could point me to some documentation, examples, since I'm quite new to maven. Thanx!
Igor Bolic
@Igor: read the free online book: http://www.sonatype.com/products/maven/documentation/book-defguide
seanizer
@Igor The link provided by @seanizer (thank you) is definitely a good place to get started. More precisely start with the first book (don't be scared by the word "book").
Pascal Thivent
@seanizer @Pascal Thanx guys for pointing me in right direction!
Igor Bolic
@igor you're welcome, but you should accept the answer too
seanizer