我的master build.gradle文件中有一个依赖项部分
subprojects {
dependencies {
}
}
然后我在我的子项目中添加一个,因为只有一个使用两个本地依赖项,并且在下面的故障中打破了所有内容
dependencies {
compile fileTree(dir: 'play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: 'play-1.2.4/framework', include: '*.jar')
}
您无法更改未处于未解决状态的配置!
谷歌搜索此错误会产生大量结果,但我似乎无法从他们那里解读如何解决这个问题?
注意:如果我注入了依赖项,这确实有效....为什么会这样?
project(':webserver') {
dependencies {
compile fileTree(dir: 'play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: 'play-1.2.4/framework', include: '*.jar')
}
}
一个重要说明:我不确定它是否重要,我的实际主构建.gradle是一行导入下一个(因为我无法得到“主”文件夹)。这可能是问题吗?
FULL master build.gradle文件
allprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
buildDir = 'output'
task hello << { task -> println "I'm $task.project.name" }
build << { task -> println "MASTER: I'm building now classpath=$sourceSets.main.compileClasspath.files" }
}
subprojects {
version = 'Developer-Build'
project.ext.genLibDir = file('lib')
project.ext.fixedLibDir = file('libother')
repositories {
mavenCentral()
}
//configurations.compile {
// exclude group: 'javax.jms', module: 'jms'
// exclude group: 'com.sun.jdmk', module: 'jmxtools'
// exclude group: 'com.sun.jmx', module: 'jmxri'
//}
dependencies {
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.1.4.Final'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.6'
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.6.6'
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.0.6'
compile group: 'joda-time', name: 'joda-time', version: '2.1'
compile group: 'com.google.inject',name: 'guice', version: '3.0'
compile group: 'com.google.protobuf',name: 'protobuf-java', version: '2.4.1'
//to be erased soon
compile group: 'commons-configuration',name:'commons-configuration',version: '1.8'
compile group: 'org.jboss.netty', name: 'netty', version: '3.2.7.Final'
//compile group: 'org.asteriskjava',name: 'asterisk-java', version: '1.0.0.M3'
compile fileTree(dir: project.ext.fixedLibDir, include: '*.jar')
}
task('copyJars') {
ext.collection = files { genLibDir.listFiles() }
delete ext.collection
copy { from configurations.compile into genLibDir }
copy { from fixedLibDir into genLibDir }
}
task('setupAll', dependsOn: ['copyJars','eclipse']) {
description = 'Update jars from remote repositories and then fix eclipse classpath for master project'
}
hello << {println "- I depend on stserver"}
build << { println "subproject:source sets=$sourceSets.main.java.srcDirs" }
}
task release << { println "putting together release" }
//TODO: have a release task AND if version is null when running the release task
//throw an exception telling the user to pass in a version with "./build -Dversion=xxxx"
//The automated build will call the release task with a version number like that
gradle.taskGraph.whenReady {taskGraph ->
if (taskGraph.hasTask(release) && version == 'Developer-Build') {
throw new StopExecutionException("You must specify -Dversion=<some version> to run the release task")
} else {
version = '1.0-SNAPSHOT'
}
}
FULL child webserver build.gradle file
sourceSets.main{
java.srcDirs = ['app']
}
build << { println "source sets=$sourceSets.main.java.srcDirs" }
hello << {println "- Do something specific xxxx"}
dependencies {
compile fileTree(dir: 'play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: 'play-1.2.4/framework', include: '*.jar')
}
eclipse {
}
感谢, 迪安
答案 0 :(得分:0)
这意味着您有一些其他代码可以在配置时解析compile
配置(即询问其文件)。类似于configurations.compile.each { ... }
,外部的任务操作。解析配置后,您无法再向其中添加依赖项。通常,在配置时解析配置是不合需要的(也是不必要的)。除此之外,它会减慢你的构建速度。
有关Gradle构建(初始化/配置/执行)的不同阶段的更多信息,请参阅Gradle user guide。