2012-06-25 25 views
0

我试图在这里下列答案tasks.setupAll.dependsOn(copyJars)在gradle中不起作用?

how to override a task making it depend on one of mine in gradle

,但它失败

无法找到任务设置属性 'setupAll'。

我已经尝试了一些东西

  1. 使子项目中的部分任务取决于主:copyJars但失败
  2. 以下解决方案
  3. 剥离的任务,没有工作。

我只有一个build.gradle文件和settings.gradle文件。设置gradle这个文件是

include 'master', 'toneserver','webserver' 

主的build.gradle文件(具体而言,搜索setupAll的两个实例为不知何故有蹊跷的是

//NOTE: Currently this file is for dependency management only but we would like 
// to convert all of the build to gradle from the ant files. We needed to add dependency 
// management so did so with gradle first as a first step in the process of evolution 

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

project(':toneserver') { 
    dependencies { 
     compile fileTree(dir: 'play-1.2.4/framework/lib', include: '*.jar') 
     compile fileTree(dir: 'play-1.2.4/framework', include: '*.jar') 

     compile project(':master') 
     compile project(':webserver') 
    } 

    task eclipse(overwrite: true) { 
    } 

} 

project(':webserver') { 
    dependencies { 
     compile fileTree(dir: 'play-1.2.4/framework/lib', include: '*.jar') 
     compile fileTree(dir: 'play-1.2.4/framework', include: '*.jar') 

     compile project(':master') 
    } 

    //playframework has it's own generation of .classpath and .project fils so do not 
    //overwrite their versions 
    task eclipse(overwrite: true) { 
    } 
} 

project(':master') { 
    project.ext.genLibDir = file('lib') 
    project.ext.fixedLibDir = file('libother') 

    repositories { 
     mavenCentral() 
    } 

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

     tasks.setupAll.dependsOn(copyJars) 
} 

subprojects { 
    version = 'Developer-Build' 

    //configurations.compile { 
    // exclude group: 'javax.jms',  module: 'jms' 
    // exclude group: 'com.sun.jdmk',  module: 'jmxtools' 
    // exclude group: 'com.sun.jmx',  module: 'jmxri' 
    //} 

    task('setupAll', dependsOn: ['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' 
    } 
} 

这是怎么回事与此?重写任务依赖于其他的东西应该工作很轻松我虽然(也许这句法仍然是错的?)

感谢, 院长

回答

0

没关系,愚蠢的错误,忘记我的任务是在子项目,应该是外并需要一个:以及如此新的setupAll在子项目之外,并且是

task('setupAll', dependsOn: [':master:copyJars', 'eclipse']) { 
    description = 'Update jars from remote repositories and then fix eclipse classpath for master project' 

}