Maven-publish plugin tasks managing with gradle 2.3

Hi. I’ve applyed “maven-publish” plugin to my project and here is publishing code block (labels is list of strings)

publishing {

publications {

labels.each { label ->

“model${label}”(MavenPublication) {

artifactId “model-${label.toLowerCase()}”

artifact tasks."${label.toLowerCase()}Jar"

artifact tasks.“source${label}Jar” {

classifier ‘sources’

}

}

}

}

repositories {

maven { name ‘snapshot’; url snapshotRepository }

maven { name ‘release’; url releaseRepository }

}

}

My goal is to create task which dependsOn all publishToSnapshotRepository tasks. In old gradle this worked:

task deliver(dependsOn: tasks.findAll { task -> task.name.endsWith(‘ToSnapshotRepository’) })

But since 2.2 and http://gradle.org/docs/2.2/release-notes#publishing-plugins-and-native-language-support-plugins-changes publishing tasks are created after afterEvaluate

I try to write:

model {

tasks.deliver.dependsOn tasks.findAll { task -> task.name.endsWith(‘ToSnapshotRepository’) })

}

but get

No signature of method: org.gradle.model.dsl.internal.NonTransformedModelDslBacking.endsWith() is applicable for argument types: (java.lang.String) values: [ToSnapshotRepository]

What should I do and where can I read more information about ‘model’ extension?

Any suggestions?

Actually the task you are configuring is your custom task not a publishing task, so in fact, you do not have to put this configuration inside the ‘model {…}’ configuration block. The key here is instead of using the default Groovy collection method ‘findAll’, you’ll want to use one the the Gradle collection methods that returns a “live” collection.

https://gradle.org/docs/current/javadoc/org/gradle/api/tasks/TaskCollection.html#matching(groovy.lang.Closure)

task deliver {

dependsOn tasks.matching { it.name.endsWith(‘toSnapshotRepository’) }

}

Thank you, Mark! Perfect solution.