如何在 gradle 中重用 pom.xml 中定义的依赖项
how do I reuse the dependencies defined in pom.xml in gradle
我想重用这个 pom.xml file 中定义的依赖项 这是一个很长的依赖项列表。为了方便起见,我想重用它。
所以我在 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 版本,但不会将任何文件导入到我的项目中。
That pom.xml does not actually define any dependencies, it only defines versions of artifacts in dependencyManagement block. Thus, depending on this artifact in Gradle does not bring any transitive dependencies in your project (neither it will in Maven, btw).
不过没关系。版本信息就够了。
这个段是我用来解决问题的。
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
} }
.......
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")
}
}
pom.xml
实际上并没有定义任何依赖项,它只定义了 dependencyManagement
block 中的工件版本。因此,依赖 Gradle 中的这个工件不会给你的项目带来任何传递依赖(顺便说一句,在 Maven 中也不会)。
您可以在 Spring's dependency management plugin 中为 Gradle 尝试什么。它允许在 Gradle.
中重用 BOM 的 dependencyManagement
块定义
我想重用这个 pom.xml file 中定义的依赖项 这是一个很长的依赖项列表。为了方便起见,我想重用它。
所以我在 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 版本,但不会将任何文件导入到我的项目中。
That pom.xml does not actually define any dependencies, it only defines versions of artifacts in dependencyManagement block. Thus, depending on this artifact in Gradle does not bring any transitive dependencies in your project (neither it will in Maven, btw).
不过没关系。版本信息就够了。
这个段是我用来解决问题的。
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
} }
.......
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")
}
}
pom.xml
实际上并没有定义任何依赖项,它只定义了 dependencyManagement
block 中的工件版本。因此,依赖 Gradle 中的这个工件不会给你的项目带来任何传递依赖(顺便说一句,在 Maven 中也不会)。
您可以在 Spring's dependency management plugin 中为 Gradle 尝试什么。它允许在 Gradle.
中重用 BOM 的dependencyManagement
块定义