Include Gradle Module in Maven Project

We have a large project that uses Maven as a build system. We decided that in future projects we will use Gradle as a more convenient tool, but we also want to use Gradle for our old project.

I think that switching from Maven to Gradle at one time will be very painful, because we have TONS code in POM files (we have really heavy build logic).

I know that Gradle has an automation tool (gradle init), but it does not work correctly (I think this tool is for small Maven projects without specific build logic).

So here is the question: can I include the Gradle module in a Maven project for migration with small steps? Maybe there is a Maven plugin that allows you to process build.gradle as a pom.xml file?

+6
source share
2 answers

There is a gradle-maven-plugin that allows you to run Gradle tasks from Maven. From the plugin description:

To use the plugin, simply declare the plugin and bind it to the maven life cycle 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 start maven, Gradle will be called and execute the "doSomething" task is defined in the build.gradle file.

Obviously, you can change the task (s) according to your needs.

In this example, the Gradle call will occur during maven's β€œcompile”, but this can easily be changed by changing the value of the element.

Not sure how to include Gradle artifacts depending on your dependencies, maybe you will need to publish this artifact to your local maven repository to make it available to your maven project.

+6
source

You can find the useful gradle-maven-share plugin. It is designed to migrate from maven to gradle by sharing the maven configuration with gradle.

+3
source

Source: https://habr.com/ru/post/1011903/


All Articles