Migrating legacy ant project to maven / gradle - maven

I have a legacy JAVA project and we use Ant to build it. We are planning to keep using ant for building the project but delegate the dependency management to maven/gradle without affecting the existing build process.
What might be the best way to move forward - with Maven or with gradle?
Since existing project has it's own structure(which may not conform to standard Maven archtypes), I know might have to make a custom archtype if using maven.
https://stackoverflow.com/a/48791837/2458858 provides one way to solve it but I am trying to find a standard solution in which I am able to delegate dependency management within the same project rather than a separate project.

Related

Using maven just for dependency management

In our project we are using ant for building the system and now we want to add dependency management to our system. I already learn that we can use ivy for this. But in future, we want to change the system into maven. But for now, we just want to handle the dependency problem. Is it possible to use maven just for dependency management and build for ant?

Edit Java source code before compile

I am new to gradle. I am looking forward to migrating from maven to gradle.
I had few requirements:
Existing project is maven based, and is generating a fat jar/uber jar. I am planning to split this into multiple projects, and creating smaller/thinner jars/libraries
I am currently evaluating the Multi-project Build support.
I have to also edit the Java source code, automatically, like making the java source modifications based on certain conditions
Publish the project as maven based, as other projects which need these split-up jars are still maven based.
I suppose Maven plugin can be used for publishing?
Would Gradle be a good, scalable solution for these two requirements which I am looking into currently?
Also please provide some pointers around these two topics.
Gradle has very good multi-project support, far better than Maven's. You can start with this documentation section
You can setup compilation of generated/auto-edited sources as well. Take a look at this forum post, discussing compilation of sources created from database using hbm2dao
You can setup publishing of projects using the Maven plugin. pom.xml files will be generated automatically

Is there any easy way to generate mave pom file from ant build

I have a ant build.xml file , how can i directly create a maven pom.xml which is exactly equivalent of build.xml file ? I know that I can create a maven project and move the folder of build.xml to appropriate folder of maven directories, But is there any automated way of doing this ?
ANT and MAVEN are different so there is probably no such complete automation really.
Still there are some attempts to automate it (see: https://github.com/ewhauser/ant2maven/blob/master/ant2maven.groovy and its forked repositories).
Another approach may be to create a pom.xml file and use https://maven.apache.org/plugins/maven-antrun-plugin/ to include the ANT script in it.
The simple answer is no. There is no easy way to generate a POM.
In my opinion switching to Maven is best left to new projects with little or no legacy to defend. In short Maven is a highly opinionated build tool that follows a standardized build workflow. ANT, on the other, ANT is gloriously configurable... resulting in no two builds working the same way :-)
A secondary problem is that few ANT builds properly record the origin and version of their 3rd party dependencies...
In most cases you are better off keeping the existing ANT build logic and introduce dependency managment using a plugin like Apache ivy. This allows an ANT project to properly integrate with a Maven repository infrastructure. This further enables collaboration with other teams using alternative build tools like Maven, Gradle or SBT.
Related answers:
Migrating complex project from Ant to Maven - How to handle unusual folder structures?
Maven or Ivy? Which one is better with a system already in production? And the other differences?

Library development/debug with Maven

I am in the processing of integrating Maven into my my projects. While maven has plenty of pros i'm finding it difficult to figure out how to maintain my current development process, which is as follows:
For creating SDKs I will create a sample app, which will depend on and directly reference the SDK source code, all from within the same code project. This means that I can make easily change/debug the SDK code with one click run/debugging.
I fear this won't really be possible with Maven. Can I create some type of Hybrid approach, where I continue my normal development approach and then push builds to Maven when it is appropriate.
Update - For Clarity
My problem is that when everything is done through maven, the dependencies are built and published to Maven. Then, the dependent project pulls down compiled references and uses them. My issues is that I don't want to go through this whole process every time I make a small change to a dependency.Thanks.
You should try creating parent level pom.xml with two modules - your library and simple app to test it. In simple app's pom.xml provide a dependency on library module.
Then open in your IDE parent pom as maven project. This should be sufficient for normal debug.
Other possible approach - install you library artifact into maven repo with sources. In this case you will be able to debug it, but test app still have to load use jars from repo.

Statically linking maven and gradle dependencies

I am using the hector & astyanax projects. These projects used to require maven, and now astyanax requires gradle.
I would like to statically link one of these projects to my java project (which is not built using maven/gradle). I am not interested in updating the version of astyanax every time they make a new release. I am not interested in mavenizing/gradelizing my own project.
So, two problems arise: 1. Getting the astyanax jars. 2. Getting the depenedency Jars.
At first, not having time to thoroughly understand maven (get off my lawn!), I copied all of the jar files in my global .maven directory into my project, and linked to them. Problem is, it's a pretty messy solution.
Is there an easier way to get all jars needed to use a gradle/maven library? (While I don't mind using gradle to build astyanax, I don't want to use it to build my own project).
Getting jars for distribution, seems like a very basic use case, am I missing a simple way here?
astyanax is published to maven central as com.netflix.astyanax:astyanax:1.56.42. Any build tool (Grails, Maven, Gradle, Buildr, SBT) that resolves from Maven can make a dependency on Astyanax and have its dependencies transitively downloaded. That fact that it's built with Gradle doesn't change how it's consumed.
From your question, it's unclear how you want to resolve these libraries. If you don't want to use a tool (Grails, Maven, Gradle, Buildr, SBT), then you'll have to manually navigate every dependencies and its dependencies from Maven Central. It's quite uncommon for a modern java project to manually download dependencies anymore, the practicalness given the complex dependencies graph make it prohibitive.

Resources