Publishing task breaks from Gradle 1.6 to 2.0, with Task with name not found


(JG Homan) #1

In Apache Samza we’re moving from gradle(w) 1.6 to 2.0 and our current build script is breaking in a rather confusing way.

We have a subproject, samza-shell, defined as follows:

project(":samza-shell") {
  apply plugin: 'java'
    configurations {
    gradleShell
  }
    // other code ellided
  task shellTarGz(type: Tar) {
     compression = Compression.GZIP
     classifier = 'dist'
    from 'src/main/bash'
    from 'src/main/resources'
  }
    artifacts {
    archives(shellTarGz) {
      name 'samza-shell'
      classifier 'dist'
    }
  }

and a separate, included maven.gradle file to publish the artifacts:

subprojects {
  apply plugin: 'maven-publish'
    publishing {
    publications {
      mavenJava(MavenPublication) {
        from components.java
          if(project.name == 'samza-shell') {
          artifact shellTarGz {
            name "samza-shell"
            classifier "dist"
          }
        }
      }
    }
  }
}

This worked fine in 1.6 but in 2.0 I’m running into

* What went wrong:
A problem occurred configuring project ':samza-shell'.
> Task with name 'shellTarGz' not found in project ':samza-shell'.

Looks like the maven plugin is now being evaluated before the samza-shell subproject and hence does not know about the shellTarGz task. Any hints on how to make it visible?


#2

The ‘maven-publish’ plugin uses our new, work-in-progress configuration mechanism, which is described in more detail at http://forums.gradle.org/gradle/topics/revolutionary_new_gradle_features_on_the_2014_roadmap.

While we improve things, sometimes the ordering of configuration can be a bit confusing. The best way to solve your use case would be to include the conditional publishing logic for the ‘samza-shell’ project in that project definition.

Sometime after the ‘maven.gradle’ file is applied, you should be able to do:

project(":samza-shell") {
  publishing {
    publications {
      mavenJava {
        artifact shellTarGz {
          name "samza-shell"
          classifier "dist"
        }
      }
    }
  }
}

We’ll be making gradual improvements to the ‘maven-publish’ plugin over the coming releases. Stay tuned.


(JG Homan) #3

I tried that, but am getting the same error. I deleted the code from the maven.gradle and inlined it right after the task and artifact definition:

task shellTarGz(type: Tar) {
     compression = Compression.GZIP
     classifier = 'dist'
    from 'src/main/bash'
    from 'src/main/resources'
  }
    artifacts {
    archives(shellTarGz) {
      name 'samza-shell'
      classifier 'dist'
    }
  }
    publishing {
    publications {
      mavenJava {
        artifact shellTarGz {
          name "samza-shell"
          classifier "dist"
        }
      }
    }
  }

(The maven.gradle is being imported via the import of gradle/environment.gradle on line 39.


#4

Can you give the full stack trace? (–stacktrace)


(JG Homan) #5

Yep, github gist


#6

Well that’s pretty odd. The underlying cause of the problem is that the ‘MavenArtifact’ does not have a ‘name’ property.

If you remove the line that attempts to set the name of the artifact, the problem goes away:

if(project.name == 'samza-shell') {
          artifact shellTarGz {
            classifier "dist"
          }
        }

But the error message when it fails is quite misleading: clearly we’ll need to work on this with the new model rules implementation.


(JG Homan) #7

OK, good to know. Thanks for tracking this down!