Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert maven pom to gradle build

I am converting one of my maven project into gradle. For doing this I am runngin following command where pom.xml is located

gradle init --type pom

But it is giving me java.lang.NullPointerException

  FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':init'.
> Could not convert Maven POM /Users/myname/Documents/oAuth+Angular/workspace/feature-oauth_and_security_69/ui/pom.xml to a Gradle build.
> Unable to create Maven project model using POM /Users/myname/Documents/oAuth+Angular/workspace/feature-oauth_and_security_69/ui/pom.xml.
  > java.lang.NullPointerException (no error message)

is there anything to perform with init or anything else i am missing?

This is my pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0   http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.test</groupId>
<artifactId>ui</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ui</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.2.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-parent</artifactId>
            <version>1.0.1.BUILD-SNAPSHOT</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zuul</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security.oauth</groupId>
        <artifactId>spring-security-oauth2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-jwt</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <scope>runtime</scope>
    </dependency>
</dependencies>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <wro4j.version>1.7.6</wro4j.version>
    <java.version>1.7</java.version>
</properties>

<build>
    <resources>
        <resource>
            <directory>${project.basedir}/src/main/resources</directory>
        </resource>
        <resource>
            <directory>${project.build.directory}/generated-resources</directory>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <!-- Serves *only* to filter the wro.xml so it can get an absolute 
                        path for the project -->
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/wro</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/wro</directory>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>ro.isdc.wro4j</groupId>
            <artifactId>wro4j-maven-plugin</artifactId>
            <version>${wro4j.version}</version>
            <executions>
                <execution>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
                <cssDestinationFolder>${project.build.directory}/generated-resources/static/css</cssDestinationFolder>
                <jsDestinationFolder>${project.build.directory}/generated-resources/static/js</jsDestinationFolder>
                <wroFile>${project.build.directory}/wro/wro.xml</wroFile>
                <extraConfigFile>${basedir}/src/main/wro/wro.properties</extraConfigFile>
                <contextFolder>${basedir}/src/main/wro</contextFolder>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.webjars</groupId>
                    <artifactId>jquery</artifactId>
                    <version>2.1.1</version>
                </dependency>
                <dependency>
                    <groupId>org.webjars</groupId>
                    <artifactId>angularjs</artifactId>
                    <version>1.3.8</version>
                </dependency>
                <dependency>
                    <groupId>org.webjars</groupId>
                    <artifactId>bootstrap</artifactId>
                    <version>3.2.0</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>http://repo.spring.io/libs-snapshot-local</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>http://repo.spring.io/libs-milestone-local</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>http://repo.spring.io/libs-release-local</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

like image 796
Krishna Verma Avatar asked Apr 08 '15 07:04

Krishna Verma


People also ask

Is POM used in Gradle?

If you really need to use both build tools, but want to maintain the dependencies in your pom. xml , you can implement the required functionality to read the dependencies in Groovy and use it in your Gradle script (you can even write a plugin). The pom. xml file is in XML format, so it should be easy to parse it.

How do I convert to Gradle?

To convert Maven to Gradle, only one command has to run is gradle init in the directory containing the POM. xml. This will convert the Maven build to a Gradle build, generating a settings.

Why is Gradle faster than Maven?

The biggest differences are Gradle's mechanisms for work avoidance and incrementality. The top 3 features that make Gradle much faster than Maven are: Incrementality — Gradle avoids work by tracking input and output of tasks and only running what is necessary, and only processing files that changed when possible.

How do I create a Gradle POM file?

You can name the task createPom to anyTaskName as you like. Then just run gradle clean or grale build or simply gradle createPom . This will generate it as pom.


3 Answers

There is a problem with <parent> element, exactly with <relativePath/> inner element in block:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.2.RELEASE</version>
    <relativePath />
</parent>

When you remove the <relativePath/> element or set it correctly, the gradle will initialize the project.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.2.RELEASE</version>
    <!-- <relativePath>../parent/pom.xml</relativePath> -->
</parent>

The problem was with the incorrectly set relativePath element, which didn't point to the parent pom file as it should.

like image 141
Benjamin Avatar answered Oct 21 '22 05:10

Benjamin


I don't know why but worked after commenting the "repositories" Thanks for all help

like image 26
Krishna Verma Avatar answered Oct 21 '22 07:10

Krishna Verma


I feel a cleaner way to convert a maven project with parent module to a gradle one is by following steps below:

  • Get an effective pom.xml for the project to pom_eff.xml:
    mvn help:effective-pom -Doutput=pom_eff.xml
  • Remove parent tag from pom_eff.xml
  • Take backup of the original pom.xml and rename pom_eff.xml to pom.xml.
  • Do gradle init

This way gradle engine gets a flattened version of the pom.xml that is far simpler to decode for the gradle system.

like image 37
Arnab Avatar answered Oct 21 '22 05:10

Arnab