HHH-15193 - Fix Gradle plugin - forcing dependency on hibernate-core SNAPSHOT
This commit is contained in:
parent
43d2274573
commit
5a4efc1c58
|
@ -76,11 +76,11 @@ task publish {
|
|||
}
|
||||
|
||||
processResources {
|
||||
inputs.property( "orm-version", getVersion() )
|
||||
filter( ReplaceTokens, tokens: [ 'hibernateVersion': getVersion() ] )
|
||||
}
|
||||
|
||||
|
||||
tasks.withType( GroovyCompile ) {
|
||||
tasks.withType( JavaCompile ) {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,7 @@ package org.hibernate.orm.tooling.gradle;
|
|||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.SourceSetContainer;
|
||||
|
||||
import org.hibernate.orm.tooling.gradle.enhance.EnhancementTask;
|
||||
import org.hibernate.orm.tooling.gradle.metamodel.JpaMetamodelGenerationTask;
|
||||
|
@ -28,25 +24,15 @@ public class HibernateOrmPlugin implements Plugin<Project> {
|
|||
project.getLogger().debug( "Adding Hibernate extensions to the build [{}]", project.getPath() );
|
||||
final HibernateOrmSpec ormDsl = project.getExtensions().create( HibernateOrmSpec.DSL_NAME, HibernateOrmSpec.class, project );
|
||||
|
||||
final Configuration hibernateOrm = project.getConfigurations().maybeCreate( "hibernateOrm" );
|
||||
project.getDependencies().add(
|
||||
"hibernateOrm",
|
||||
project.provider( () -> "org.hibernate.orm:hibernate-core:" + HibernateVersion.version )
|
||||
);
|
||||
project.getConfigurations().getByName( "implementation" ).extendsFrom( hibernateOrm );
|
||||
|
||||
final JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin( JavaPluginConvention.class );
|
||||
assert javaPluginConvention != null;
|
||||
|
||||
final SourceSetContainer sourceSets = javaPluginConvention.getSourceSets();
|
||||
final SourceSet mainSourceSet = sourceSets.getByName( SourceSet.MAIN_SOURCE_SET_NAME );
|
||||
|
||||
EnhancementTask.apply( ormDsl, mainSourceSet, project );
|
||||
JpaMetamodelGenerationTask.apply( ormDsl, mainSourceSet, project );
|
||||
EnhancementTask.apply( ormDsl, ormDsl.getSourceSetProperty().get(), project );
|
||||
JpaMetamodelGenerationTask.apply( ormDsl, ormDsl.getSourceSetProperty().get(), project );
|
||||
|
||||
project.getDependencies().add(
|
||||
"implementation",
|
||||
project.provider( () -> "org.hibernate.orm:hibernate-core:" + ormDsl.getHibernateVersionProperty().get() )
|
||||
ormDsl.getHibernateVersionProperty().map( (ormVersion) -> Character.isDigit( ormVersion.charAt( 0 ) )
|
||||
? "org.hibernate.orm:hibernate-core:" + ormVersion
|
||||
: null
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,9 @@ import org.gradle.api.Action;
|
|||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.ExtensionAware;
|
||||
import org.gradle.api.plugins.ExtensionContainer;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
import org.hibernate.orm.tooling.gradle.enhance.EnhancementSpec;
|
||||
import org.hibernate.orm.tooling.gradle.metamodel.JpaMetamodelGenerationSpec;
|
||||
|
@ -26,6 +28,8 @@ public abstract class HibernateOrmSpec implements ExtensionAware {
|
|||
public static final String DSL_NAME = HIBERNATE;
|
||||
|
||||
private final Property<String> hibernateVersionProperty;
|
||||
private final Project project;
|
||||
private final Property<SourceSet> sourceSetProperty;
|
||||
private final Property<Boolean> supportEnhancementProperty;
|
||||
private final Property<Boolean> supportJpaMetamodelProperty;
|
||||
|
||||
|
@ -34,11 +38,15 @@ public abstract class HibernateOrmSpec implements ExtensionAware {
|
|||
|
||||
|
||||
@Inject
|
||||
@SuppressWarnings( "UnstableApiUsage" )
|
||||
public HibernateOrmSpec(Project project) {
|
||||
this.project = project;
|
||||
|
||||
hibernateVersionProperty = project.getObjects().property( String.class );
|
||||
hibernateVersionProperty.convention( HibernateVersion.version );
|
||||
|
||||
sourceSetProperty = project.getObjects().property( SourceSet.class );
|
||||
sourceSetProperty.convention( mainSourceSet( project ) );
|
||||
|
||||
supportEnhancementProperty = project.getObjects().property( Boolean.class );
|
||||
supportEnhancementProperty.convention( true );
|
||||
|
||||
|
@ -49,6 +57,15 @@ public abstract class HibernateOrmSpec implements ExtensionAware {
|
|||
jpaMetamodelDsl = getExtensions().create( JpaMetamodelGenerationSpec.DSL_NAME, JpaMetamodelGenerationSpec.class, this, project );
|
||||
}
|
||||
|
||||
private static SourceSet mainSourceSet(Project project) {
|
||||
return resolveSourceSet( SourceSet.MAIN_SOURCE_SET_NAME, project );
|
||||
}
|
||||
|
||||
private static SourceSet resolveSourceSet(String name, Project project) {
|
||||
final JavaPluginExtension javaPluginExtension = project.getExtensions().getByType( JavaPluginExtension.class );
|
||||
return javaPluginExtension.getSourceSets().getByName( name );
|
||||
}
|
||||
|
||||
public Property<String> getHibernateVersionProperty() {
|
||||
return hibernateVersionProperty;
|
||||
}
|
||||
|
@ -61,6 +78,26 @@ public abstract class HibernateOrmSpec implements ExtensionAware {
|
|||
hibernateVersionProperty.set( version );
|
||||
}
|
||||
|
||||
public Property<SourceSet> getSourceSetProperty() {
|
||||
return sourceSetProperty;
|
||||
}
|
||||
|
||||
public void setSourceSet(String name) {
|
||||
setSourceSet( resolveSourceSet( name, project ) );
|
||||
}
|
||||
|
||||
public void setSourceSet(SourceSet sourceSet) {
|
||||
sourceSetProperty.set( sourceSet );
|
||||
}
|
||||
|
||||
public void sourceSet(String name) {
|
||||
setSourceSet( resolveSourceSet( name, project ) );
|
||||
}
|
||||
|
||||
public void sourceSet(SourceSet sourceSet) {
|
||||
setSourceSet( sourceSet );
|
||||
}
|
||||
|
||||
public Property<Boolean> getSupportEnhancementProperty() {
|
||||
return supportEnhancementProperty;
|
||||
}
|
||||
|
|
|
@ -33,16 +33,17 @@ import static org.hibernate.orm.tooling.gradle.HibernateOrmSpec.HIBERNATE;
|
|||
public class EnhancementTask extends DefaultTask {
|
||||
public static final String DSL_NAME = "hibernateEnhance";
|
||||
|
||||
public static void apply(HibernateOrmSpec ormDsl, SourceSet mainSourceSet, Project project) {
|
||||
public static void apply(HibernateOrmSpec pluginDsl, SourceSet mainSourceSet, Project project) {
|
||||
final EnhancementTask enhancementTask = project.getTasks().create(
|
||||
DSL_NAME,
|
||||
EnhancementTask.class,
|
||||
ormDsl,
|
||||
pluginDsl,
|
||||
mainSourceSet,
|
||||
project
|
||||
);
|
||||
enhancementTask.setGroup( HIBERNATE );
|
||||
enhancementTask.setDescription( "Performs Hibernate ORM enhancement of the project's compiled classes" );
|
||||
enhancementTask.onlyIf( (t) -> pluginDsl.getSupportEnhancementProperty().getOrElse( true ) );
|
||||
|
||||
final String compileJavaTaskName = mainSourceSet.getCompileJavaTaskName();
|
||||
final Task compileJavaTask = project.getTasks().getByName( compileJavaTaskName );
|
||||
|
@ -55,10 +56,8 @@ public class EnhancementTask extends DefaultTask {
|
|||
private final DirectoryProperty outputDirectory;
|
||||
|
||||
@Inject
|
||||
@SuppressWarnings( "UnstableApiUsage" )
|
||||
public EnhancementTask(HibernateOrmSpec ormSpec, SourceSet mainSourceSet, Project project) {
|
||||
this.enhancementDsl = ormSpec.getEnhancementSpec();
|
||||
|
||||
public EnhancementTask(HibernateOrmSpec pluginDsl, SourceSet mainSourceSet, Project project) {
|
||||
enhancementDsl = pluginDsl.getEnhancementSpec();
|
||||
javaCompileOutputDirectory = mainSourceSet.getJava().getDestinationDirectory();
|
||||
|
||||
outputDirectory = project.getObjects().directoryProperty();
|
||||
|
|
|
@ -297,7 +297,7 @@ public class JpaMetamodelGenerationTask extends DefaultTask {
|
|||
}
|
||||
|
||||
@SuppressWarnings( "UnstableApiUsage" )
|
||||
public static void apply(HibernateOrmSpec ormDsl, SourceSet mainSourceSet, Project project) {
|
||||
public static void apply(HibernateOrmSpec pluginDsl, SourceSet mainSourceSet, Project project) {
|
||||
final String mainCompileTaskName = mainSourceSet.getCompileJavaTaskName();
|
||||
final JavaCompile mainCompileTask = (JavaCompile) project.getTasks().getByName( mainCompileTaskName );
|
||||
final Task compileResourcesTask = project.getTasks().getByName( "processResources" );
|
||||
|
@ -305,13 +305,14 @@ public class JpaMetamodelGenerationTask extends DefaultTask {
|
|||
final JpaMetamodelGenerationTask genTask = project.getTasks().create(
|
||||
DSL_NAME,
|
||||
JpaMetamodelGenerationTask.class,
|
||||
ormDsl,
|
||||
pluginDsl,
|
||||
mainSourceSet,
|
||||
mainCompileTask,
|
||||
project
|
||||
);
|
||||
genTask.setGroup( HIBERNATE );
|
||||
genTask.setDescription( "Generates the JPA 'static metamodel'" );
|
||||
genTask.onlyIf( (t) -> pluginDsl.getSupportJpaMetamodelProperty().getOrElse( true ) );
|
||||
|
||||
genTask.dependsOn( mainCompileTask );
|
||||
genTask.dependsOn( compileResourcesTask );
|
||||
|
@ -324,8 +325,8 @@ public class JpaMetamodelGenerationTask extends DefaultTask {
|
|||
genTask.finalizedBy( compileJpaMetamodelTask );
|
||||
mainCompileTask.finalizedBy( compileJpaMetamodelTask );
|
||||
compileJpaMetamodelTask.dependsOn( genTask );
|
||||
compileJpaMetamodelTask.source( project.files( ormDsl.getJpaMetamodelSpec().getGenerationOutputDirectory() ) );
|
||||
compileJpaMetamodelTask.getDestinationDirectory().set( ormDsl.getJpaMetamodelSpec().getCompileOutputDirectory() );
|
||||
compileJpaMetamodelTask.source( project.files( pluginDsl.getJpaMetamodelSpec().getGenerationOutputDirectory() ) );
|
||||
compileJpaMetamodelTask.getDestinationDirectory().set( pluginDsl.getJpaMetamodelSpec().getCompileOutputDirectory() );
|
||||
compileJpaMetamodelTask.setClasspath(
|
||||
project.getConfigurations().getByName( "runtimeClasspath" ).plus( mainSourceSet.getRuntimeClasspath() )
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue