2

我的主 bu​​ild.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')
    }
}

一个重要注意事项:我不确定这是否重要,我的实际主 build.gradle 是导入以下一个的一行(因为我无法让“主”文件夹工作)。这可能是问题吗?

完整的主 bu​​ild.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'
    }
}

完整的子网络服务器 build.gradle 文件

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 {
    }

谢谢,院长

4

1 回答 1

0

这意味着您有一些其他代码可以compile在配置时解析(即要求其文件)配置。类似configurations.compile.each { ... }任务动作之外。解析配置后,您无法向其添加更多依赖项。通常在配置时解析配置是不可取的(也是不必要的)。除其他外,它会减慢您的构建速度。

有关 Gradle 构建的不同阶段(初始化/配置/执行)的更多信息,请参阅Gradle 用户指南

于 2012-06-22T20:11:22.740 回答