2017-09-01 79 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的依賴管理插件非常有用,並有助於解決版本問題。 –