In Gradle1.5 get error using sources configuration in artifacts ('Could not find method sources()')


(richard murray) #1

HI,

We’ve just upgraded to Gradle.1.5 (from 1.4) and we are getting the following error.

A problem occurred evaluating script.
> Could not find method sources() for arguments [task ':CM:packageSources', javabuild_4gk1hp1h9pj70smenaqqhte1bp$_run_cl
osure6_closure9@2c205e57] on project ':CM'.

Here’s the gradle file. The ‘sources’ configruation is used to package and upload source JAR’s into an Ivy repository. This works OK in Gradle 1.4 and I didn’t spot anything in the Gradle 1.5 release notes (or user guide) to explain the error.

apply plugin: 'java'
  //gradle assumes java source code is in /src/main/java (a Maven convention) override this to use our 'src' directories
sourceSets.main.java.srcDirs = ['src']
sourceSets.main.resources.srcDirs = ['src']
sourceSets.test.java.srcDirs = ['test']
sourceSets.test.resources.srcDirs = ['test']
  configurations {
    sources
}
          dependencies {
    testCompile libs.junit
}
  task packageSources(type: Jar) {
    from sourceSets.main.allSource
    classifier = 'sources'
    }
    artifacts {
    sources (packageSources) {
        type = 'source'
    }
}
        //upload jar to Ivy repository
uploadArchives {
    repositories {
        add project.repositories.ivy_ois_repo
    }
}
      //upload jar to Ivy repository
uploadSources {
    repositories {
        add project.repositories.ivy_ois_repo
    }
}
  uploadArchives.dependsOn /* uploadJavadocs, */ uploadSources

(richard murray) #2

I’ve managed to workaround the error by renaming my configuration from ‘sources’ to ‘sourceCode’ and updating the gradle file as follows.

I’d still like to know if I am doing something wrong or if this is simply a change that hasn’t been documented.

Thanks.

apply plugin: ‘java’

//gradle assumes java source code is in /src/main/java (a Maven convention) override this to use our ‘src’ directories sourceSets.main.java.srcDirs = [‘src’] sourceSets.main.resources.srcDirs = [‘src’] sourceSets.test.java.srcDirs = [‘test’] sourceSets.test.resources.srcDirs = [‘test’]

configurations {

sourceCode }

dependencies {

testCompile libs.junit }

task packageSourceCode(type: Jar) {

from sourceSets.main.allSource

classifier = ‘sources’

}

artifacts {

sourceCode (packageSourceCode) {

type = ‘source’

} }

//upload jar to Ivy repository uploadArchives {

repositories {

add project.repositories.ivy_ois_repo

} }

//upload jar to Ivy repository uploadSourceCode {

repositories {

add project.repositories.ivy_ois_repo

} }

uploadArchives.dependsOn /* uploadJavadocs, */ uploadSourceCode <.code>