Gradle build.gradle to Maven pom.xml

I have a Gradle project and I need all its dependencies to be transferred and used with another Maven project. In other words how can I generate (or can I generate) the pom.xml from the build.gradle?


The most built in solution would likely be to use the archiveTask task in the Maven Plugin which will generate a pom in the poms folder in your build dir.

When using Gradle's Maven plugin, the install task is automatically added to your tasks, and calling it will always generate a POM file.

So if your build.gradle file looks like this:

apply plugin: 'java'
apply plugin: 'maven'

group = 'myGroup'
// artifactId is taken by default, from folder name
version = '0.1-SNAPSHOT'

dependencies {
  compile 'commons-lang:commons-lang:2.3'

you can call gradle install in its folder, you will find in the build/poms subfolder, a file called pom-default.xml which will contain the dependencies. Also, the built JAR together with the POM will be in your Maven local repo.

As I didn't want to install anything in my local repo, I did following, instead, after reading docs. Add in your build.gradle

apply plugin: 'maven'

group = ''
// artifactId is taken by default, from folder name
version = '0.0.1-SNAPSHOT'

task writeNewPom << {
    pom {
        project {
            inceptionYear '2014'
            licenses {
                license {
                    name 'The Apache Software License, Version 2.0'
                    url ''
                    distribution 'repo'

to run it gradle writeNewPom


gradle being made with groovy can try to add after ending } project block

      groupId 'org.apache.maven.plugins'
      artifactId 'maven-compiler-plugin'
          source '1.8'
          target '1.8'

didn't try, wild guess !

When you have no gradle installed the "write gradle task to do this' is not very userful. Instead of installing this 100MB beast with dependecies I made the filter converting gradle dependencies to maven dependencies:

cat build.gradle\
| awk '{$1=$1};1'\
| grep -i "compile "\
| sed -e "s/^compile //Ig" -e "s/^testCompile //Ig"\
| sed -e "s/\/\/.*//g"\
| sed -e "s/files(.*//g"\
| grep -v ^$\
| tr -d "'"\
| sed -e "s/\([-_[:alnum:]\.]*\):\([-_[:alnum:]\.]*\):\([-+_[:alnum:]\.]*\)/<dependency>\n\t<groupId>\1<\/groupId>\n\t<artifactId>\2<\/artifactId>\n\t<version>\3<\/version>\n<\/dependency>/g"

This converts

compile 'org.slf4j:slf4j-api:1.7.+'
compile 'ch.qos.logback:logback-classic:1.1.+'
compile 'commons-cli:commons-cli:1.3'



The rest of pom.xml should be created by hand.

Need Your Help

Make Errors: Missing Includes in C++ Script?

c++ linux makefile qmake

I just got help in how to compile this script a few mintues ago on SO but I have managed to get errors. I am only a beginner in C++ and have no idea what the below erros means or how to fix it.

On the nature of Information and Entropy definitions


I was looking at the Shannon's definitions if intrinsic information and entropy (of a "message").