簡體   English   中英

gradle 2.8子項目依賴項-未找到compile()

[英]gradle 2.8 subproject dependencies - compile() not found

我有一個root gradle項目和10個子項目。 我只想在根項目中指定5個依賴項,而不必將其復制粘貼到所有10個模塊中。 如果我寫:

subprojects{
  dependencies{
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    compile 'org.springframework:spring-core:4.1.2.RELEASE'
    compile 'org.springframework:spring-context:4.1.2.RELEASE'
  }
}

它告訴我尚未找到compile()方法。 如何使其工作,所以我應該只在一個地方指定部門?

您是否將Java插件應用於:

allprojects {
   apply plugin: 'java'
}

要么:

subprojects {
   apply plugin: 'java'
}

請記住,您還需要添加存儲庫塊。 這將是:

repositories {
   mavenCentral()
   jcenter()
}

Gradle Doc參考: 8.2。 聲明你的依賴

您必須像這樣用dependencies關鍵字包裝編譯依賴性:

subprojects {
  dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    compile 'org.springframework:spring-core:4.1.2.RELEASE'
    compile 'org.springframework:spring-context:4.1.2.RELEASE'
  }
}

這也適用於僅根目錄的庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM