将maven pom转换为渐变构建

将maven pom转换为渐变构建,maven,gradle,converter,maven-3,Maven,Gradle,Converter,Maven 3,我正在将我的一个maven项目转换为gradle。为此,我将按照pom.xml所在的命令运行 gradle init --type pom 但它给了我java.lang.NullPointerException FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':init'. > Could not convert Maven POM /Users/mynam

我正在将我的一个maven项目转换为gradle。为此,我将按照pom.xml所在的命令运行

gradle init --type pom
但它给了我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)
是否有需要使用init执行的内容或我缺少的其他内容

这是我的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>

4.0.0
组织测试
用户界面
0.0.1-快照
罐子
用户界面
SpringBoot的演示项目
org.springframework.boot
spring启动程序父级
1.2.2.1发布
org.springframework.cloud
SpringCloudStarter父级
1.0.1.1构建快照
聚甲醛
进口
org.springframework.cloud
春云始祖
org.springframework.cloud
SpringCloudStarter安全
org.springframework.boot
SpringBootStarterWeb
org.springframework.security.oauth
spring-security-oauth2
org.springframework.security
spring security jwt
org.springframework.boot
弹簧起动试验
测试
org.apache.httpcomponents
httpclient
运行时
UTF-8
1.7.6
1.7
${project.basedir}/src/main/resources
${project.build.directory}/生成的资源
org.springframework.boot
springbootmaven插件
maven资源插件
复制资源
验证
复制资源
${basedir}/target/wro
src/main/wro
真的
ro.isdc.wro4j
wro4j maven插件
${wro4j.version}
产生资源
跑
ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory
${project.build.directory}/generated resources/static/css
${project.build.directory}/generated resources/static/js
${project.build.directory}/wro/wro.xml
${basedir}/src/main/wro/wro.properties
${basedir}/src/main/wro
org.webjars
jquery
2.1.1
org.webjars
安格拉斯
1.3.8
org.webjars
独自创立
3.2.0
春季快照
春季快照
http://repo.spring.io/libs-snapshot-local
真的
春季里程碑
春季里程碑
http://repo.spring.io/libs-milestone-local
假的
春假
春假
http://repo.spring.io/libs-release-local
假的

块中的
元素存在问题,正是
内部元素存在问题:

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

org.springframework.boot
spring启动程序父级
1.2.2.1发布
当您删除
元素或正确设置它时,gradle将初始化项目

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

org.springframework.boot
spring启动程序父级
1.2.2.1发布

问题在于设置的relativePath元素不正确,它没有像应该的那样指向父pom文件。

我不知道为什么,但在注释了“存储库”之后工作了 感谢Gradle页面中的所有帮助

注意Gradle不支持依赖项的POM中的导入范围,因此您必须使用上述语法手动导入它们


我觉得将带有父模块的maven项目转换为gradle项目的更简洁的方法是通过以下步骤:

  • 获取项目的有效pom.xml到pom_eff.xml:
    mvn帮助:有效的pom-Doutput=pom_eff.xml
  • 从pom_eff.xml中删除父标记
  • 备份原始pom.xml并将pom_eff.xml重命名为pom.xml
  • 做梯度初始化

通过这种方式,gradle引擎获得了pom.xml的扁平版本,对于gradle系统来说,该版本的解码要简单得多

Gradle init任务不仅允许您创建新的骨架项目,而且还将自动将现有的Maven项目转换为Gradle项目。您只需运行命令


是否可以发布POM文件?请使用--debug gradle init--type POM重试--debug@MikeD你在检查它吗?你能试着删除wro4j maven插件并再次尝试转换吗?除了这个插件,POM对我来说很好。我想这就是原因。@dunni在删除wro4j maven插件后出现了同样的异常删除存储库不起作用,就像我刚才尝试的那样。也没有提到relativePath父解决方案。考虑1——这是一个孵化的特征,2——指定你正在使用的工具版本,通过代码>等级-V<代码>删除存储库对我也不起作用。我没有,但仍然失败。我试图删除,但没有任何帮助。这对我来说是可行的,但我需要删除pom_eff.xml中的标记。在运行
gradle build的案例中,根本不处理依赖项<