convert maven pom to gradle build
Solution 1
I don't know why but worked after commenting the "repositories" Thanks for all help
Solution 2
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.
Solution 3
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.
Related videos on Youtube
Comments
-
Krishna Verma almost 2 years
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>
-
Mike D about 9 yearsis it possible for you to post your POM file?
-
-
Mike D about 9 yearsRemoving the repositories doesn't work, as I've just tried. Nor does the relativePath parent solution mentioned. Consider 1- this is an incubating feature, 2- specifying the versions of tools your are using via
gradle -v
-
John Zhang over 6 yearsI don't have the <relativePath> but still failed. I tried to delete <repositories> but it doesn't help.
-
John Zhang over 6 yearsRemoving the repositories doesn't work for me either.
-
John Zhang over 6 yearsThis works for me but I need to remove the <projects> tag in the pom_eff.xml.
-
Marian Klühspies over 6 yearsNot doing anything at all with the dependencies in my case
-
Heinz almost 6 years
gradle inti
doesn't do anything for the dependencies defined in the root project POM file, so all subprojects fail -
Heinz almost 6 yearsrunning
gradle build
afterwards does not do anything