Classpath used for tasks from an external plugin defined in a script plugin

Hi,

I want to define an external gradle file (“script plugin” I believe is the correct term) that uses a buildscript element to import a plugin and then use tasks from that plugin. Once I discovered I needed to use the fully qualified plugin name I thought I had got this working but I now get a class not found issue. The plugin I am using (WebSphere Liberty) depends on a couple of other JARs and as you can see in the error message below it is the class from the wlp-anttasks.jar file that cannot be found.

[ERROR] [org.gradle.BuildExceptionReporter] > taskdef class net.wasdev.wlp.ant.ServerTask cannot be found

These are my two build files to recreate this:

build.gradle

apply plugin: ‘java’
repositories { mavenCentral(); }
dependencies {
testCompile ‘junit:junit:4.12’
}

apply from: ‘depends.gradle’

depends.gradle

apply plugin: net.wasdev.wlp.gradle.plugins.Liberty

buildscript {
repositories {
mavenCentral()
maven {
name = ‘Sonatype Nexus Snapshots’
url = ‘https://oss.sonatype.org/content/repositories/snapshots/
}
}
dependencies {
classpath ‘net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:1.0-SNAPSHOT’
}
}

build.dependsOn libertyStart,libertyStop
libertyStop.mustRunAfter libertyStart

If I put all the plugin loading and buildscript code into the build.gradle file then it works fine (and I can keep the calls to the tasks in depends.gradle as well) but I’d really like to keep all of the setup for interacting with the plugin in the same file.

Looking at the logs (with --info on) I can see these dependencies are loaded but there is a slight variation in the output:

working case log output

10:34:30.862 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching :GradleDepends:unspecified(classpath) to its parents.
10:34:30.863 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:1.0-SNAPSHOT(default) to its parents.
10:34:30.864 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching net.wasdev.wlp.ant:wlp-anttasks:1.1-SNAPSHOT(compile) to its parents.
10:34:30.864 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching net.wasdev.wlp.ant:wlp-anttasks:1.1-SNAPSHOT(master) to its parents.
10:34:30.865 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching net.wasdev.wlp.ant:wlp-anttasks:1.1-SNAPSHOT(runtime) to its parents.
10:34:30.866 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant:1.8.4(compile) to its parents.
10:34:30.867 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant:1.8.4(master) to its parents.
10:34:30.869 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant:1.8.4(runtime) to its parents.
10:34:30.870 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant-launcher:1.8.4(compile) to its parents.
10:34:30.871 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant-launcher:1.8.4(master) to its parents.
10:34:30.872 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant-launcher:1.8.4(runtime) to its parents.

Failing case log ouput

10:36:09.482 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching unspecified:unspecified:unspecified(classpath) to its parents.
10:36:09.482 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:1.0-SNAPSHOT(default) to its parents.
10:36:09.482 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching net.wasdev.wlp.ant:wlp-anttasks:1.1-SNAPSHOT(compile) to its parents.
10:36:09.483 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching net.wasdev.wlp.ant:wlp-anttasks:1.1-SNAPSHOT(master) to its parents.
10:36:09.483 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching net.wasdev.wlp.ant:wlp-anttasks:1.1-SNAPSHOT(runtime) to its parents.
10:36:09.483 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant:1.8.4(compile) to its parents.
10:36:09.483 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant:1.8.4(master) to its parents.
10:36:09.483 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant:1.8.4(runtime) to its parents.
10:36:09.484 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant-launcher:1.8.4(compile) to its parents.
10:36:09.484 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant-launcher:1.8.4(master) to its parents.
10:36:09.484 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.resolveengine.graph.ResolvedConfigurationDependencyGraphVisitor] Attaching org.apache.ant:ant-launcher:1.8.4(runtime) to its parents.

To my untrained eye it looks like when it is working the classpath is being attached to the project whereas in the failing case it is not being added to the project. I find it odd though that it can find the libertyStart task though as I would have thought all the external dependencies would suffer the same problem rather than just ones deeper in the dependency hierarchy.

I’ve seen a couple of quite old forum posts such as here:

that suggest that I can only add buildscript blocks to the main build.gradle file, is that still the case? Are there any plans to change this limitation? If this is still the case should the docs be updated to include this limitation.

Thanks!

Iain

You certainly can have buildsript blocks in external scripts, although I do notice for some plugins it doesn’t work. I haven’t investigated deeply enough but for example we have the jfrog build-info plugin and config in an artifactory.gradle called from the main build.gradle. It has its own buildscript, e.g.

buildscript { repositories { jcenter() } dependencies { classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1') } }

apply plugin: 'maven-publish’
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPublicationsPlugin

but another example of using asciidoctor plugin I had to add it to the buildscript {} of the root build.gradle but could apply the plugin in the external script (documentation.gradle)

// Apply asciidoctor plugin - requires plugin on root build.gradle buildscript{} classpath
apply plugin: 'org.asciidoctor.convert’

We also use some of our own internal plugins in buildscript{} of externally included scripts.
I didn’t realise this was unsupported if thats what Peter is referring to but it works for some and not for others - maybe I’m missing something.