Import Maven Project as Dependency into Gradle Project - java

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.

Related

How can I use gradle project in maven project as dependecy

I have one Gradle module I need to use inside a Maven project as a dependency. Can you suggest to me how I can achieve this?

Export maven as jar file with all dependencies

I have my own java library created as maven project and has some dependencies included in pom.xml
I want to export project as jar and include it into others maven projects.
The problem is that I need to copy all dependencies from pom.xml of my library into maven projects where is imported my library to make it to work.
How to export my library to not be necessary to copy dependencies of my library.
That is easy to do; the central feature of Maven is that it manages the project dependencies for you.
You need to mvn install your project from the command line; that will install the jar and the pom files to your local repository.
You can then include your library as a Maven dependency in other Maven based projects; Maven will resolve the (transitive) dependencies for your project.
Normally you don't need to list all the dependencies in the project that imports your library. Maven should fetch them for you. What you need to do is to declare dependencies in your library.
Make sure you declare correct types of dependencies. Here is more info. In your case you need to make sure that dependencies you want to copy to the downstream projects are marked as 'compile'
There are tools that make 'Fat' jars by copying all dependencies inside. But they are mostly used to build the final project such as a deployable WAR file or a desktop app. Not in case of the libraries

Having build.gradle next to pom.xml

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.

What are the options of joining the external library in Android using Gradle?

For example: there is a project on GitHub https://github.com/chrisbanes/ActionBar-PullToRefresh, it uses Gradle, so you can add to a project using:
compile 'com.github.chrisbanes.actionbarpulltorefresh: library: +'
And there is a project https://github.com/ahorn/android-rss, where Gradle is not used.
What are the ways to connect using Gradle this library to my project?
This need not to store external libraries in my git repository.
If you have a project that is not a simple Java project and is not made for gradle Im afraid you have to download the source convert an eclipse adt project manually/automatically to gradle:
You cann import it as a module through Android Studio (New-> Module -> Import Existing Project) see http://developer.android.com/sdk/installing/migrate.html
You could also just write the build files yourself teaching you a little gradle on the way, just look at the examples and docs how to do it
This project doesn't use gradle but uses maven so dependency to this project can also be handled. You just need to find repository with public access where this project is deployed and add appropriate address in repositories section in build.gradle file. If there's no such repository You can download the project and install it in the local repository - the downside is that no other developer that works with your project can download this dependency until You make Your repo public.
Furthermore the fact that some project doesn't use gradle or maven doesn't mean that dependency to this project can't be handled with gradle. If this project has fixed versioning scheme and is accessible over the net gradle can be configured to use such dependency. Gradle can deal with multiple types of repositories (e.g. flat files).

Import jar from ant ivy project to maven

I am working on an ant project and i want to use the jar created by it , in my maven project.
The ant project employs ivy to manage its dependency.
Is there any easy way to do this if possible without changing any code on their side.
It sounds like you want to be able to publish artefacts generated by your ivy-based project to a maven repo so they can be resolved by the mvn-based project.
Try http://draconianoverlord.com/2010/07/18/publishing-to-maven-repos-with-ivy.html
Once the ivy-based project has published its artefacts to the mvn repo, then the mvn-based project should be able to resolve the published artefacts.

Categories

Resources