Gradle init: Convert plugin tag in POM to gradle task

Hi,

I’m a newbie to gradle. We have a maven multi-project build, which we are migrating to gradle build. gradle init seems to not translate the POM containing plugin configuration (inside tag) into corresponding task in build.gradle

Because of this we are having to convert all the plugin configurations from POM to build.gradle manually.

Is there any way we could convert those tags in pom.xml into build.gradle? Is there a list of POM tags which ‘gradle init’ can’t translate into build.gradle?

There’s hundreds of maven plugins

  • Some are core maven plugins
  • Some are developed by third parties
  • Some do not have a Gradle equivalent plugin
  • Some have two or three Gradle plugin equivalents
  • Some have maven configuration which is quite different from the Gradle equivalent configuration
  • Many maven plugins are not required in Gradle (a core gradle task an/or a snippet of groovy can often do the job)

For these reasons it’s difficult (impossible) to convert maven plugin declarations to the equivalent gradle script. Only a handful of plugins (if any) are supported for auto conversion by the Gradle init plugin.

Unfortunately you’ll need to do the plugin conversion manually yourself.

Thanks @Lance,

Maven properties in tag of pom.xml are not getting converted by gradle init. Is it expected behaviour?

And some of the dependencies in converted build.gradle file are missing when compared to pom.xml. Does this mean gradle init converts some of the stuff partially?

Is the working and behavior of ‘gradle init’ is documented somewhere?

Thanks.

Maven properties in tag of pom.xml are not getting converted by gradle init. Is it expected behaviour

Yes

And some of the dependencies in converted build.gradle file are missing when compared to pom.xml

This is strange, gradle init should bring in all dependencies. Can you show <dependency> declaration in pom.xml which is missing from build.gradle?

Is the working and behavior of ‘gradle init’ is documented somewhere?

I’ve not found one, from what I know all it does is

  1. Convert <dependency>
  2. Apply “java” plugin for packaging=jar
  3. Apply “war” plugin for packaging=war

Thanks for the reply @Lance,

Can you show <dependency> declaration in pom.xml which is missing from build.gradle ?

Here’s the dependencies of pom:

<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>my-ssn-sw</artifactId>
        <version>${project.version}</version>
        <type>war</type>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>my-ssn-client</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>my-ssn-model</artifactId>
        <version>${project.version}</version>
    </dependency>
</dependencies>

Converted build.gradle:

dependencies {
    compile 'com.example.myproject:my-ssn-client:1.00-SNAPSHOT'
}
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>my-ssn-sw</artifactId>
        <version>${project.version}</version>
        <type>war</type>
    </dependency>

What does maven do with dependencies with type=war? Does it put the war file in WEB-INF/lib? or does it unzip it and combine it with your sources? I’ve never seen a type=war dependency before. This is possibly an edge case that maven supports that Gradle doesn’t know how to handle. It feels like a bit of an anti-pattern to me (eg how do jars packed inside the war participate in dependency resolution?)

I’m not sure about the other missing dependency. Is this a local project in a multi module build? Or a totally separate project published/referenced from a repository?

Is there anything in the Gradle logs saying why the dependency was omitted?