我只是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
我已经改变了'项目( ':域')...''到项目( ':域' ){compileJava.dependsOn(':infrastructure:build')}',所以他在开始编译域项目之前建立了基础设施项目。但他仍然找不到包... – Walle 2011-06-07 13:51:47
奇怪......我没有看到任何错误。顺便说一句,你不需要添加基础设施项目作为testCompile范围的依赖; testCompile从编译中继承。 – 2011-06-07 14:36:39
您是否尝试使用基础架构的测试类?如果是,那就是问题所在。当您依赖于基础架构时,gradle只会将基础结构的类而不是其测试类放到类路径中。让我知道如果是这样,我会写一个答案。 – 2011-06-07 17:19:25