Skip to content

Commit

Permalink
HHH-15707 - Fix Gradle plugin with Kotlin 1.7.0 or higher
Browse files Browse the repository at this point in the history
Since Kotlin version 1.7.0 the KotlinCompile task no longer extends
Gradle's AbstractCompile.

This commit updates Hibernate Gradle enhancement plugin to not cast to
AbstractCompile and instead use reflection to invoke the
"getDestinationDirectory" method.

It also updates the Kotlin version on used to test the Gradle
enhancement (but remains backwards compatible with previous Kotlin
versions).
  • Loading branch information
tomas-c authored and beikov committed Feb 6, 2023
1 parent 0fc4060 commit 41c6a70
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.hibernate.orm.tooling.gradle;

import java.lang.reflect.Method;
import java.util.Set;

import org.gradle.api.Action;
Expand Down Expand Up @@ -69,21 +70,26 @@ private void prepareEnhancement(HibernateOrmSpec ormDsl, Project project) {

for ( String language : languages ) {
final String languageCompileTaskName = sourceSet.getCompileTaskName( language );
final AbstractCompile languageCompileTask = (AbstractCompile) project.getTasks().findByName( languageCompileTaskName );
final Task languageCompileTask = project.getTasks().findByName( languageCompileTaskName );
if ( languageCompileTask == null ) {
continue;
}

//noinspection Convert2Lambda
languageCompileTask.doLast( new Action<>() {
languageCompileTask.doLast(new Action<>() {
@Override
public void execute(Task t) {
final DirectoryProperty classesDirectory = languageCompileTask.getDestinationDirectory();
final ClassLoader classLoader = Helper.toClassLoader( sourceSet, project );

EnhancementHelper.enhance( classesDirectory, classLoader, ormDsl, project );
try {
final Method getDestinationDirectory = languageCompileTask.getClass().getMethod("getDestinationDirectory");
final DirectoryProperty classesDirectory = (DirectoryProperty) getDestinationDirectory.invoke(languageCompileTask);
final ClassLoader classLoader = Helper.toClassLoader(sourceSet, project);
EnhancementHelper.enhance(classesDirectory, classLoader, ormDsl, project);
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
} );
});
}
} );
}
Expand Down

0 comments on commit 41c6a70

Please sign in to comment.