Gradle strange behavior when extending sourceSets with Map variable

We are developing a Java project that is capable of handling (modifying) class files at build time. We have defined a Gradle task that calls a java based Ant task that takes inputDir (like build / classes) and outputDir (like build / classes-instrumented) and possible other parameters. The task is called separately for the main and test class files after compilation. Since the "normal" java sourceSet doesn't fit, our first thought was to implement our own source, but couldn't find an easy way. A reasonable alternative, similar to ANTLR etc., seemed to be additional variables. Since I needed several, I went to get Karta.

sourceSets.all { ext.instrumentation = [:] }

sourceSets.all {
    instrumentation.inputDir = null
    instrumentation.outputDir = null
    instrumentation.classPath = null

def postfix = '-instrumented'


Below you can see how we initialize the variables.

sourceSets {
    main {
        instrumentation.inputDir = sourceSets.main.output.classesDir
        instrumentation.outputDir = instrumentation.inputDir + postfix
        instrumentation.classPath = sourceSets.main.output + configurations.compile

    test {
        instrumentation.inputDir = sourceSets.test.output.classesDir
        instrumentation.outputDir = instrumentation.inputDir + postfix


However it does not work with "Could not find main () method for arguments [build_f2cvmoa3v4hnjefifhpuk6ira $ _run_closure5_closure23 @ 12a14b74] for root project" Continuations ".

We are using Gradle 2.1

I have the following questions:

  • any idea why the first one fails?
  • Is an extra variable a reasonable solution to the problem?

Many thanks for your help


source to share

1 answer

solution : install the latest version.

I had the same problem, I read the gradle documentation for gradle 3, but gradle 2.7 was installed.

  • marked gradle version 2.7
  • then read gradle 2.7 doc

    but didn't find any information about sourceSet in java plugin for that version
  • gradle 3 installed -> problem solved


All Articles