[GRADLE-3558] Applying a plugin built with Gradle 2.x through ProjectBuilder can't find internal classes Created: 15/Sep/16  Updated: 30/Sep/16  Resolved: 30/Sep/16

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 3.2-rc-1

Type: Bug
Reporter: Benjamin Muschko Assignee: Unassigned
Resolution: Fixed Votes: 2

Known Issue Of:
3.0

 Description   

Discussion originated on the Gradle forum.

Every custom task that implements DefaultTask automatically uses internal classes. With 3.0 the internal class DynamicObject was moved from one package to another. Usually that's not a big reason for concern as long as Gradle ensures binary compatibility before releasing new version. Executing a plugin contain a custom task built with 2.x still works with Gradle 3.0.

The issue arises if the plugin is applied in a test that uses ProjectBuilder. The user sees the following issue:

Caused by: java.lang.NoClassDefFoundError: org/gradle/api/internal/DynamicObject
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.getDeclaredMethods(Class.java:1975)
	at org.gradle.internal.reflect.ClassInspector.inspectClass(ClassInspector.java:67)
	at org.gradle.internal.reflect.ClassInspector.visitGraph(ClassInspector.java:51)
	at org.gradle.internal.reflect.ClassInspector.inspect(ClassInspector.java:31)
	at org.gradle.api.internal.AbstractClassGenerator.inspectType(AbstractClassGenerator.java:260)
	at org.gradle.api.internal.AbstractClassGenerator.inspectType(AbstractClassGenerator.java:216)
	at org.gradle.api.internal.AbstractClassGenerator.generateUnderLock(AbstractClassGenerator.java:95)
	... 82 more
Caused by: java.lang.ClassNotFoundException: org.gradle.api.internal.DynamicObject
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 91 more

ProjectBuilder uses is own hierarchy of ClassLoaders that do not resemble the ones we use when executing a build script with the Gradle runtime through the command line or the Tooling API.


Generated at Wed Jun 30 12:51:56 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.