2011-06-07 30 views
1

我只是Gradle的新手,我對它有一個小問題。我試圖建立兩個項目(稱爲「基礎設施」和「域」),其中域從基礎設施進行一些導入。Gradle:在build中找不到包

當我嘗試構建這兩個項目時,Gradle無法編譯我的域項目,因爲他無法從基礎結構中找到包。

這是我的build.gradle:

subprojects{ 
    apply plugin: 'java' 

    springversion = '3.0.4.RELEASE' 
    hibernateversion = '3.4.0.GA' 
    jsfversion = '2.0.3' 
    projectid = 'com.companyName.projectName' 
    projectversion = '1.0.0-SNAPSHOT' 

    repositories { 
     mavenRepo urls: 'file:///C:/companyName/m2repo' 
     mavenCentral() 
    } 

    dependencies { 
     compile group: 'commons-configuration', name: 'commons-configuration', version: '1.6' 
     compile group: 'sample.plugin', name: 'hsqldb-maven-plugin', version: '1.0-SNAPSHOT' 
     testCompile group: 'junit', name: 'junit', version: '4.8.2' 
     testCompile group: 'org.mockito', name: 'mockito-core', version: '1.8.0' 
     testCompile group: 'org.springframework', name: 'spring-test', version: springversion 

     compile group: 'org.springframework', name: 'spring-context', version: springversion 
     compile group: 'org.springframework', name: 'spring-orm', version: springversion 
     compile group: 'org.springframework', name: 'spring-web', version: springversion 
     compile group: 'org.hibernate', name: 'hibernate-annotations', version: hibernateversion 
     compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: hibernateversion 
     compile group: 'org.hibernate', name: 'ejb3-persistence', version: '1.0.2.GA' 
     compile group: 'javax.enterprise', name: 'cdi-api', version: '1.0-CR1' 
     compile group: 'com.sun.faces', name: 'jsf-api', version: jsfversion 
     compile group: 'commons-lang', name: 'commons-lang', version: '2.5' 
     runtime group: 'org.slf4j', name: 'slf4j-api', version: '1.5.6' 
     runtime group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.5.6' 
     runtime group: 'org.hsqldb', name: 'hsqldb', version: '1.8.0.10' 
     runtime group: 'commons-dbcp', name: 'commons-dbcp', version: '1.2.2' 
     runtime group: 'org.aspectj', name: 'aspectjweaver', version: '1.6.2' 
    } 

} 

project (':infrastructure'){ 
    task intTestJar(type: Jar) { 
     from sourceSets.main.classes 
     from sourceSets.test.classes 
    } 
} 

project(':domain'){ 
    compileJava.dependsOn (':infrastructure:intTestJar')   
} 

在我settings.gradle,我已經聲明這一點:

include 'infrastructure', 'domain' 

這兩個項目應該建立一個.jar文件。

當試圖建立的項目,顯示此錯誤時,他正在運行的域:compileTestJava

package com.companyName.projectName.test does not exist 

這個包是指我的基礎設施項目。在eclipse中它可以工作,但我不能用gradle構建它。

任何幫助,將不勝感激。

問候,

WALLE

+0

我已經改變了'項目( ':域')...''到項目( ':域' ){compileJava.dependsOn(':infrastructure:build')}',所以他在開始編譯域項目之前建立了基礎設施項目。但他仍然找不到包... – Walle 2011-06-07 13:51:47

+1

奇怪......我沒有看到任何錯誤。順便說一句,你不需要添加基礎設施項目作爲testCompile範圍的依賴; testCompile從編譯中繼承。 – 2011-06-07 14:36:39

+1

您是否嘗試使用基礎架構的測試類?如果是,那就是問題所在。當您依賴於基礎架構時,gradle只會將基礎結構的類而不是其測試類放到類路徑中。讓我知道如果是這樣,我會寫一個答案。 – 2011-06-07 17:19:25

回答

-1

這奏效了:

subprojects{ 
    apply plugin: 'java' 
    apply plugin: 'eclipse' 

    springversion = '3.0.4.RELEASE' 
    hibernateversion = '3.4.0.GA' 
    jsfversion = '2.0.3' 
    projectid = 'com.companyName.projectName' 
    projectversion = '1.0.0-SNAPSHOT' 

    repositories { 
     mavenRepo urls: 'file:///C:/companyName/m2repo' 
     mavenCentral() 
    } 

    dependencies { 
     compile group: 'commons-configuration', name: 'commons-configuration', version: '1.6' 
     compile group: 'sample.plugin', name: 'hsqldb-maven-plugin', version: '1.0-SNAPSHOT' 
     testCompile group: 'junit', name: 'junit', version: '4.8.2' 
     testCompile group: 'org.mockito', name: 'mockito-core', version: '1.8.0' 
     testCompile group: 'org.springframework', name: 'spring-test', version: springversion 

     compile group: projectid, name: 'infrastructure', version: projectversion 
     compile group: projectid, name: 'domain', version: projectversion 
     compile group: 'org.springframework', name: 'spring-context', version: springversion 
     compile group: 'org.springframework', name: 'spring-orm', version: springversion 
     compile group: 'org.springframework', name: 'spring-web', version: springversion 
     compile group: 'org.hibernate', name: 'hibernate-annotations', version: hibernateversion 
     compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: hibernateversion 
     compile group: 'org.hibernate', name: 'ejb3-persistence', version: '1.0.2.GA' 
     compile group: 'javax.enterprise', name: 'cdi-api', version: '1.0-CR1' 
     compile group: 'com.sun.faces', name: 'jsf-api', version: jsfversion 
     compile group: 'commons-lang', name: 'commons-lang', version: '2.5' 
     runtime group: 'org.slf4j', name: 'slf4j-api', version: '1.5.6' 
     runtime group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.5.6' 
     runtime group: 'org.hsqldb', name: 'hsqldb', version: '1.8.0.10' 
     runtime group: 'commons-dbcp', name: 'commons-dbcp', version: '1.2.2' 
     runtime group: 'org.aspectj', name: 'aspectjweaver', version: '1.6.2' 
    } 
    test{ 
     maxParallelForks=2 
    } 
} 

project(':infrastructure'){ 
    task infrastructureTestJar(type: Jar) { 
     from sourceSets.main.classes 
     from sourceSets.test.classes 
    } 
    infrastructureTestJar.dependsOn(jar) 
} 

project(':domain'){ 
    compileJava.dependsOn(':infrastructure:build') 
    dependencies{ 
     compile files('../infrastructure/build/libs/infrastructure.jar') 
    } 
    task domainTestJar(type: Jar) { 
     from sourceSets.main.classes 
     from sourceSets.test.classes 
    } 
    domainTestJar.dependsOn(jar) 
} 
+17

您可以總結一下您在build.gradle文件中所做的顯着更改嗎? – HairOfTheDog 2013-06-05 20:07:08