Reputation: 3409
We have a maven multi-module project, that we want to gradually migrate over to a gradle-project.
For starters, I would like to migrate only a few sub-projects to gradle, but keep them as sub-projects to the parent maven-project build.
Is there a supported/recommended way to this?
Pointers to plugins, or any advice how to best do this appreciated.
Upvotes: 6
Views: 1919
Reputation: 93
Add this to the gradle project that you're trying to build,
uploadArchives {
repositories {
mavenLocal()
}
}
Then call gradle build publishToMavenLocal
this will build the project/module and push it to the local maven repo (.m2) as well as a generated pom file. Then you can use it as your previous normal maven module with the pom file.
Read from https://proandroiddev.com/tip-work-with-third-party-projects-locally-with-gradle-961d6c9efb02 to know more.
Upvotes: 0
Reputation: 4711
In order to install the built artifact to your local maven repo, just add the maven plugin for gradle to your build.gradle
file. Then, use the install
task instead of doSomething
in @Stanislav's pom.xml example.
Upvotes: 3
Reputation: 28126
Not really sure, that there is a straightforward solution for such a task. But you can take a look at the gradle-maven-plugin which allows to run Gradle tasks in Maven. From the plugin description:
To use the plugin, simply declare the plugin and bind it to the maven lifecycle phase of your choice:
<plugin> <groupId>org.fortasoft</groupId> <artifactId>gradle-maven-plugin</artifactId> <version>1.0.8</version> <configuration> <tasks> <!-- this would effectively call "gradle doSomething" --> <task>doSomething</task> </tasks> </configuration> <executions> <execution> <!-- You can bind this to any phase you like --> <phase>compile</phase> <goals> <!-- goal must be "invoke" --> <goal>invoke</goal> </goals> </execution> </executions> </plugin>
Now when you run maven, gradle will be invoked and execute the "doSomething" task defined in build.gradle.
Obviously you can change the task(s) to suit your needs.
In this example, the gradle invocation will happen during the maven "compile" phase, but this can be easily changed by changing the element value.
Unfortunately can't say, how to share the Gradle module artifacts without posting it to some local repository.
Upvotes: 4