HHH-15557 fix problem when orm plugin is applied before Java plugin

This commit is contained in:
Christian Ambach 2024-08-08 15:48:11 +02:00 committed by Christian Ambach
parent 54c1c4a2d9
commit acceb10043
1 changed files with 19 additions and 15 deletions

View File

@ -14,7 +14,7 @@ import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.plugins.JvmEcosystemPlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.SourceSet;
import org.hibernate.orm.tooling.gradle.enhance.EnhancementHelper;
@ -25,24 +25,28 @@ import org.hibernate.orm.tooling.gradle.enhance.EnhancementHelper;
public class HibernateOrmPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
// for SourceSet support and other JVM goodies
project.getPlugins().apply( JvmEcosystemPlugin.class );
project.getPlugins().withType( JavaPlugin.class, javaPlugin -> {
project.getLogger().debug( "Adding Hibernate extensions to the build [{}]", project.getPath() );
final HibernateOrmSpec ormDsl = project.getExtensions().create( HibernateOrmSpec.DSL_NAME, HibernateOrmSpec.class, project );
project.getLogger().debug( "Adding Hibernate extensions to the build [{}]", project.getPath() );
final HibernateOrmSpec ormDsl = project.getExtensions().create(
HibernateOrmSpec.DSL_NAME,
HibernateOrmSpec.class,
project
);
prepareEnhancement( ormDsl, project );
prepareHbmTransformation( ormDsl, project );
prepareEnhancement( ormDsl, project );
prepareHbmTransformation( ormDsl, project );
//noinspection ConstantConditions
project.getDependencies().add(
"implementation",
ormDsl.getUseSameVersion().map( (use) -> use
? "org.hibernate.orm:hibernate-core:" + HibernateVersion.version
: null
)
);
//noinspection ConstantConditions
project.getDependencies().add(
"implementation",
ormDsl.getUseSameVersion().map( (use) -> use
? "org.hibernate.orm:hibernate-core:" + HibernateVersion.version
: null
)
);
} );
}
private void prepareEnhancement(HibernateOrmSpec ormDsl, Project project) {