I tried to make my own gradle plugin and I have one problem: gradleApi() provides an ‘org.apache.maven:maven-ant-tasks’ artifact and I can successfully compile my code with any class/interface from this artifact, but in runtime gradle will crash while loading my own class with the next stacktrace:
Caused by: java.lang.ClassNotFoundException: org.apache.maven.artifact.ant.InstallDeployTaskSupport
I have tried other classes from this artifact - same result.
Dump of classpath dependencies also show that no one dependency with ‘ant’ keyword exists in buildscript’s classloader
buildscript.configurations.getByName('classpath').files.findAll { it.absolutePath.contains('ant') }.each { println(it) }
But from other side many classes in gradle impl uses this artifact without any problems.
I tried to manually add this artifact to classpath, but then some plexus functional have broken state.
I think it’s a bug and all artifacts (which provides gradleApi()) should be available in buildscript’s classpath.
The only reliably way to tell if a class loader can load a particular class is to call ‘loadClass’. ‘maven-ant-tasks’ is an internal dependency. The fact that ‘gradleApi()’ brings in too many things is a known limitation. Declaring ‘maven-ant-tasks’ as a build script or plugin dependency sounds like the correct approach.
But if I manually add ‘maven-ant-tasks’ to my classpath i get a verifyerror:
Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
my.package.Publisher.publish(Lorg/gradle/api/publish/maven/internal/publisher/MavenNormalizedPublication;Lorg/gradle/api/artifacts/repositories/MavenArtifactRepository;)V @35: invokeinterface
Reason:
Type 'org/gradle/api/publication/maven/internal/ant/CustomDeployTask' (current frame, stack[1]) is not assignable to 'org/apache/maven/artifact/ant/InstallDeployTaskSupport'
Current Frame:
bci: @35
flags: { }
locals: { 'my.package.Publisher', 'org/gradle/api/publish/maven/internal/publisher/MavenNormalizedPublication', 'org/gradle/api/artifacts/repositories/MavenArtifactRepository', 'org/gradle/api/publication/maven/internal/ant/CustomDeployTask', 'org/gradle/api/publication/maven/internal/ant/EmptyMavenSettingsSupplier' }
stack: { 'org/gradle/api/publication/maven/internal/ant/EmptyMavenSettingsSupplier', 'org/gradle/api/publication/maven/internal/ant/CustomDeployTask' }
Bytecode:
0000000: b200 0712 082c b900 0903 002a b600 0a4e
0000010: 2db8 000b b600 0cbb 000d 59b7 000e 3a04
0000020: 1904 2db9 000f 0200 2a2d 2cb6 0010 2a2d
0000030: 2b2a b400 06b4 0011 b700 122a 2db7 0013
0000040: 1904 b900 1401 00b1
Can you provide a small, self-contained example?
Yep: https://drive.google.com/file/d/0BxcxDFWRyauQTXVhNWhGbkpJMGc/edit?usp=sharing
Example of output in ‘example.log’ file.
And yes I know about buildSrc, but it’s more real situation when my plugin is packaged in jar and available for downloading from repositories.