2017-09-01 21 views
-1

我想重用在此pom.xml file中定义的依赖关系这是相当长的依赖关系列表。我想重用它以方便。如何重用在gradle中的pom.xml中定义的依赖关系

所以我在的build.gradle文件中加入这样一行。:

dependencies { 
    // unfortunately, Gradle seems just ignore this line. 
    compile("org.activiti:activiti-ui-root:6.0.0") 
} 

但似乎刚刚的gradle这个则会忽略行。如果我不想重写一长串依赖关系,那么重用pom文件的最佳方法是什么?

请给我一些建议,非常感谢。

==============================

感谢,所有你们。最后我发现“io.spring.gradle:dependency-management-plugin”有助于解决我的问题。

@madhead是对的。 pom.xml只提供了jar版本,但不会将任何文件导入到我的项目中。

pom.xml实际上并未定义任何依赖关系,它仅定义了dependencyManagement块中的工件版本。因此,根据Gradle中的这个工件不会在你的项目中带来任何传递依赖(这在Maven中也不会)。

但是没关系。版本信息就够了。

这部分是我用来解决我的问题。

buildscript { 

repositories { 
    mavenCentral() 
    jcenter()  
} 

dependencies { 
    classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE" 
} } 

.......

项目( ':编辑图像发生器'){

dependencyManagement { 
    imports { 
     // import the pom.xml from outside. 
    mavenBom "org.activiti:activiti-ui-root:6.0.0" 
    } 
} 

dependencies { 
     // It's good to see that, you don't need to specify the version here. 
     // with the mavenBom imported above, you can always get the right version. 
    compile("org.activiti:activiti-bpmn-model") 
    testCompile("org.activiti:activiti-bpmn-converter") 
    compile("org.activiti:activiti-image-generator") 
    compile("org.imgscalr:imgscalr-lib:4.2") 
    compile("org.slf4j:slf4j-api") 
    testCompile("commons-io:commons-io") 
    testCompile("junit:junit") 
} 

}

+0

https://docs.gradle.org/current/userguide/artifact_dependencies_tutorial.html – nullpointer

+0

我没有尝试,但我认为你可以实现它。在Gradle设置文件中,您可以实现函数来读取xml pom文件,获取所有依赖关系,然后将它们作为Gradle依赖关系加载。这只是一个想法。 –

+1

你为什么认为Gradle忽略这条线?你的'build.gradle'其余部分是怎么样的? –

回答

0

pom.xml实际上并没有定义任何依赖关系它只在dependencyManagement block中定义了工件的版本。因此,根据Gradle中的这个工件不会在你的项目中带来任何传递依赖(这在Maven中也不会)。

你可以尝试在Spring's dependency management plugin为Gradle。它允许在Gradle中重复使用dependencyManagement块定义。

+0

谢谢@madhead,你是对的。你的信息有很大帮助。 Spring的依赖管理插件非常有用,并有助于解决版本问题。 –