简体   繁体   中英

How to package an Ant project with Maven?

In the project I'm working on, there's a extenal dependency that's not avaliable on the public Maven artifact index, but there's a public repository with the project code. The project is natively built using ant .

What we are planning to do is to automatically download the dependency code, provide it with a POM file, then build it as a part of our big project, which is Maven based.

So far I've managed to create a POM file that compiles the dependency using maven-ant-plugin but I've been unable to install the project into a local Maven repository, mvn install skips the jar and classes compiled using ant and just installs an empty dummy jar.

Googling so far gave no results, everybody suggests to rearrange the code to fit the default maven directory structure and just build it using maven, but this would make updating the dependency from upstream impossible, because then I would have to rearrange the files again when the new upstream version is released.

The goal is to have a POM file that I can put into the root of the ant project, update the version number, and do mvn install and have the compiled jar avaliable in the local maven repository.

How do I make maven recognize the ant-compiled jar or the ant-compiled classes?

I suggest you use the install:install-file goal.

It allows you to explicitly state which jar and which POM should be installed.

I once did it in the very same way: Added a POM that first builds everything through Ant and then calls the install-file goal for the generated artifact.

The best practice is:

  1. Try to contact the project and ask them to release the library to Maven Central (eg using Ant Ivy )
  2. If this is not possible/ process is to slow, host the library in your Maven Repository Manager (such as Nexus ) using some coordinates (groupId, artifactId, version) you choose and is unlikely to conflict with one published on Maven Central

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM