Having build.gradle next to pom.xml - java

I've had a java maven project, and now I converted to gradle because I have to write some cutom build script.
I'm wondering if I still need to keep pom.xml. Do I need to add my dependencies to pom.xml, or I should get rid of pom.xml and add them to build.gradle ? Does gradle replace maven ?

Gradle and Maven are two different build systems. They are quite the same but have some differences. But if you convert your maven project to gradle, then your pom.xml is useless from now on. You can easily convert your maven project to gradle using gradle's incubating feature with this command gradle init --type pom. Then your scripts will be added to build.gradle file. This is still an incubating feature though. You can also do it from stract. I suggest you to read the following document.

Related

Import Maven Project as Dependency into Gradle Project

I went through this link to import a gradle project as dependency into another gradle project. Is there a way to include a maven project as dependency into a gradle project?
If that Maven project is built somewhere else and deployed to a Maven repository, you can specify the artifact it produces as a simple compile dependency. If this Maven project is somehow a subproject of a Gradle multi-project build, I suppose you could hack it to work by simply ignoring the Maven POM file and perhaps adding a build.gradle to that project.
To use the solution described on the link that you provided - both projects must be gradle and included in gradle settings. Therefore you can use project closure to compile and depend on the project without building it explicitly.
I am not aware of any way to do this with maven project. I understand you use some maven plugins that you dont want to rewrite in gradle as simply can not find any equivalents etc. Often had that problem.
In this scenario I would suggest to build maven project and depend on a built jar in your gradle project.
Otherwise you could probably amend sourcesets in your gradle project to include maven classes. But I think it would be to complicated.
If I would be you I would turn it into gradle and try to replicate what you had using maven or just build the artifact and depend on it in dependencies closure.
Gradle is not that new anymore and there are many plugins that are superseding old good maven stuff.

Gradle: Comparing maven and gradle artifacts built from the same source

There's an incubating feature in gradle for comparing builds (documentation here). The documentation states it can compare:
A Gradle build with a build executed by another tool such as Apache Ant, Apache Maven or something else (i.e. migrating to Gradle).
I'd like to use this feature but the documentation doesn't outline how to do it. I'd like to build the same source code twice, once with maven then with gradle and compare the built artifact (a jar).
I've generated a build.gradle using gradle-init --type pom now i'd like to
Run the gradle build (build.gradle)
Run the maven build (pom.xml)
Compare the jars built by both
I don't mind if I need two duplicate copies of the source code to achieve this. I'd like to automate the process so that it's repeatable as I migrate my build from maven to gradle.

A gradle plugin that adds dependencies and a sample project in the same project

I want to create, in the same project, so that my IDE allows me to code them all, the following subprojects :
a java package
a gradle plugin that adds a dependency on the java project (artifact)
a gradle sample that uses this plugin
The problem is that the sample, to be evaluated, will need to use the plugin, then the plugin will add the dependency.
BUT, to compile the java package, I need all the subprojects to be evaluated...including the sample. And the sample can't be evaluated as it needs the java dependency...
How can I do ?
I didn't find anyway to get all 3 subprojects in the same project. I tried configuration on demand but the buildScript of the sample still is evaluated. My only work around is to remove the sample subproject from the project.

How to track error for compile error in eclipse?

I have maven java project that is compiled fine in command line, but when I import in eclipse I receive compilation errors about CollectionUtils.
org.apache.commons.collections.CollectionUtils
Seems that project has transitive dependencies that has reference to old versions of apache commons collections.
How to track exactly error?
How to fix?
Thanks.
Perhaps you could track down the transitive dependencies by issuing mvn dependency:tree to figure out which dependency in your pom is pulling in the older version of Apache commons.
Alternatively, inside eclipse when you open the pom.xml file (with the m2e plugin installed) you should see the Dependency Tree tab at the bottom of the Editor like so :
In the Search field you could type the name of the apache commons jar to find out which dependency is pulling it in. Once you have that add the appropriate exclusion add it should all be peachy.
Question
How did you import the maven project inside eclipse. Did you do a mvn eclipse:eclipse and then import it as a normal eclipse project ? If so, I would recommend installing the m2e plugin (linked above) and then importing the maven project using Import Existing Maven Project from within eclipse.
Looks to me like the classpath (.classpath file) in Eclipse is not correctly configured. You can have maven configure this for you by using the Maven Eclipse Plugin. Simply execute the following from the command line:
mvn eclipse:eclipse
Maven will then correctly fill the .classpath file with all dependencies (including transitive dependencies) defined in your POM. Then refresh the project in Eclipse and all of the red crosses should disappear (hopefully...)
How to track exactly error? How to fix?
invoke
mvn clean compile -e
it will give you error stacktrace that would help you to fix this error

Eclipse maven to manage only dependencies and nothing more

Is it possible for maven plugin to manage only dependencies and nothing more.
I work with "strange" maven project, and want Eclipse/maven plugin only to read dependencies from pom.xml and add it to project classpath. And nothing more.
I don't want it to set exclusion filters, source folders and output folders, or to overwrite other dependencies.
Also, pom.xml is not located in the source folder of Eclipse project. I know I could use mvn eclipse:eclipse task manually, but it mess with my .classpath and .project files, which I don't want to merge manually.
To summary, I want that all dependencies from pom.xml are automatically managed by plugin, but for plugin not to touch anything else.
EDIT: The problem is that whenever something in pom.xml changes, maven plugin changes my project configuration.
EDIT: It has to be maven since there is already pom.xml which I can replace with sbt or ivy or lein or anything eles.
Does it have to be maven? If you don't need any of the plugins, or project organisation you could use apache ivy instead.
Or you could use a even more simple one like SBT
if you have to use maven, just strip out the plugins from the pom.xml file and only add the dependencies and repos and use an IDE to launch the aplication or create a jar.
you will need to run mvn commands thought if you change the dependencies.

Categories

Resources