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?
-
Possible duplicate of [add maven repository to build.gradle](http://stackoverflow.com/questions/20574111/add-maven-repository-to-build-gradle) – Jorge Campos Oct 17 '16 at 20:58
-
Or maybe duplicate of this other one: http://stackoverflow.com/questions/16671277/maven-dependencies-with-android-studio-gradle – Jorge Campos Oct 17 '16 at 20:58
-
@JorgeCampos: In examples provided by you jar is being imported from maven repo. I want the project to be added. – Punter Vicky Oct 17 '16 at 21:01
-
I think, not sure though, you can't do that. At least I never see that in any project. My guess is that you will have to get the source code from the maven project you want and create a new project in you AS. Please add this description to your question so I can retract the duplicate vote. Something like "I don't want to import a maven project, I want to turn a maven project into a gradle project". As of now your question clearly states that you want it as a dependency. – Jorge Campos Oct 17 '16 at 21:06
-
@JorgeCampos : I don't want to turn a maven project into gradle project. I have a maven project. I want to import this project as depedency instead of creating a jar out of the maven project and importing the jar as a dependency. In the link that I have provided , it talks about the steps to follow to import another gradle project as a dependency. – Punter Vicky Oct 17 '16 at 21:10
-
@PunterVicky: _Why_ do you want to do this? If your gradle project uses classes from the Maven project, it is much easier und much more standard to build the jar from the Maven project (to the local repository or some other repository you set up) and declare this jar as a dependency in Gradle (as Gradle reads Maven repositories without a problem) – J Fabian Meier Oct 18 '16 at 07:18
-
Does this help: https://stackoverflow.com/questions/35795250/maven-project-as-dependency-in-gradle-project/35796615#35796615 – tomasulo Nov 24 '16 at 14:02
2 Answers
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.

- 14,317
- 20
- 94
- 199
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.

- 6,865
- 3
- 28
- 47