2

I want to integrate a maven project into my gradle build process. Although I was successful in converting the maven project (which is a war overlay project) into a gradle project, there are several drawbacks doing this. First of all the maven tomcat plugin can easily create a runnable jar with an embedded tomcat instance. I could not find a gradle plugin which does this job. To solve the problem I see four different approaches, I wonder which one would be the best or if there is another possibility.

  1. Convert maven project to gradle. As mentioned before this works, but I could not find a way to create a jar with embedded tomcat with this approach.
  2. The maven project will have an additional build.gradle which has tasks to execute the maven goals (for example ant.exec)
  3. I use maven for all my projects (not really an option for me)
  4. Use maven as root project and execute gradle tasks from maven

Any other ideas or suggestions?

Christian Metzler
  • 2,971
  • 5
  • 24
  • 30

3 Answers3

1

You could:

  1. Create a java application using tomcat embedded
  2. Use the gradle shadow plugin to create an executable über jar for the java application
lance-java
  • 25,497
  • 4
  • 59
  • 101
  • 1
    Found a much easier solution using combination of org.scaldingspoon.gradle:gradle-waroverlay-plugin and the gretty plugin. Now I can build my war-overlay with gradle and create an archive containing a tomcat server, the war file and start/stop scripts. It does not produce a runnable jar, but easy enough to manage by using the scripts. – Christian Metzler Feb 12 '15 at 10:53
1

After investigating some time, I want to answer the question by myself. I think converting the maven project to a gradle project in this special case isn't the best approach. I decided to use the second approach:

The war-overlay project is still a maven project but I also add a gradle.build file to the project. The build script looks like this:

task mvnPackage(type:Exec) {
    commandLine "${mavenHome}/mvn", 'package'
}

task mvnClean(type: Exec) {
    commandLine "${mavenHome}/mvn", 'clean'
}

clean.dependsOn mvnClean

assemble.dependsOn mvnPackage

So if I use gradle as build tool, maven goals will be executed, which works perfectly.

Christian Metzler
  • 2,971
  • 5
  • 24
  • 30
  • If using this approach, you might want to [declare the artifact](http://gradle.org/docs/current/userguide/artifact_management.html#N156D1) in gradle so that it is aware of the jar – lance-java Feb 11 '15 at 11:14
0

I'm not sure how reliable this is but you can also instantiate and execute some maven mojos without needing the maven container/harness (details here)

I'm not sure if this is possible with the maven tomcat mojo.

lance-java
  • 25,497
  • 4
  • 59
  • 101