简体   繁体   English

如何在gradle中重用pom.xml中定义的依赖项

[英]how do I reuse the dependencies defined in pom.xml in gradle

I want to reuse the dependencies defined in this pom.xml file It's quite a long list of dependices. 我想重用此pom.xml文件中定义的依赖项。依赖项列表很长。 I want to reuse it for convenience. 为了方便起见,我想重用它。

so I added a line in my build.gradle file like this.: 所以我在build.gradle文件中这样添加了一行:

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

But it seems that gradle just ingore this line. 但是,似乎gradle只是融入了这条线。 What's the best way of reusing a pom file if I don't want to rewrite a long list of dependencies? 如果我不想重写一长串依赖项,重用pom文件的最佳方法是什么?

Please give me some advise, many thanks. 请给我一些建议,非常感谢。

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

Thanks, all you guys. 谢谢大家 finally I find "io.spring.gradle:dependency-management-plugin" helps to solve my problem. 最后,我发现“ io.spring.gradle:dependency-management-plugin”有助于解决我的问题。

@madhead is right. @madhead是正确的。 pom.xml just provide the version of jars, but will not import any file into my project. pom.xml仅提供jar的版本,但不会将任何文件导入到我的项目中。

That pom.xml does not actually define any dependencies, it only defines versions of artifacts in dependencyManagement block. 该pom.xml实际上没有定义任何依赖关系,它仅在dependencyManagement块中定义了工件的版本。 Thus, depending on this artifact in Gradle does not bring any transitive dependencies in your project (neither it will in Maven, btw). 因此,依靠Gradle中的此工件,不会在您的项目中带来任何传递性依赖关系(在Maven中也不会)。

but it's OK. 但没关系。 the version information is enough. 版本信息就足够了。

This segment is what I use to solve my problem. 这是我用来解决问题的部分。

buildscript {

repositories {
    mavenCentral()
    jcenter()     
}

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

....... .......

project(':editor-image-generator') { project(':editor-image-generator'){

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")
}

} }

That pom.xml does not actually define any dependencies, it only defines versions of artifacts in dependencyManagement block . pom.xml实际上并没有定义任何依赖关系,它仅在dependencyManagement块中定义了工件的版本。 Thus, depending on this artifact in Gradle does not bring any transitive dependencies in your project (neither it will in Maven, btw). 因此,依靠Gradle中的此工件,不会在您的项目中带来任何传递性依赖关系(在Maven中也不会)。

What you can try in Spring's dependency management plugin for Gradle. 您可以在Spring的 Gradle 依赖性管理插件中尝试什么。 It allows to reuse that dependencyManagement block definition for BOMs in Gradle. 它允许为Gradle中的BOM重用那个dependencyManagement块定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM