From f82d381fe3b6f4a9cb6c0fdfb0dcd1de63d51cb4 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 15 Mar 2022 12:15:56 -0500 Subject: [PATCH] Gradle build clean-ups - re-organize release task definitions to avoid use of subproject iteration --- documentation/documentation.gradle | 3 + gradle/java-module.gradle | 47 ++------ gradle/module.gradle | 2 +- gradle/published-java-module.gradle | 14 ++- gradle/releasable.gradle | 7 ++ release/release.gradle | 13 +- .../hibernate-gradle-plugin.gradle | 3 +- tooling/project-template/README.adoc | 6 - .../project-template/project-template.gradle | 112 ------------------ .../src/template/resources/README.adoc | 5 - .../src/template/resources/build.gradle.kts | 80 ------------- .../template/resources/settings.gradle.kts | 32 ----- .../java/org/your/domain/SimpleEntity.java | 38 ------ .../java/org/your/domain/EntityTests.java | 54 --------- .../src/test/resources/log4j.properties | 7 -- 15 files changed, 33 insertions(+), 390 deletions(-) create mode 100644 gradle/releasable.gradle delete mode 100644 tooling/project-template/README.adoc delete mode 100644 tooling/project-template/project-template.gradle delete mode 100644 tooling/project-template/src/template/resources/README.adoc delete mode 100644 tooling/project-template/src/template/resources/build.gradle.kts delete mode 100644 tooling/project-template/src/template/resources/settings.gradle.kts delete mode 100644 tooling/project-template/src/template/resources/src/main/java/org/your/domain/SimpleEntity.java delete mode 100644 tooling/project-template/src/template/resources/src/test/java/org/your/domain/EntityTests.java delete mode 100644 tooling/project-template/src/template/resources/src/test/resources/log4j.properties diff --git a/documentation/documentation.gradle b/documentation/documentation.gradle index b8cc208a45..1da3d5f667 100644 --- a/documentation/documentation.gradle +++ b/documentation/documentation.gradle @@ -13,6 +13,8 @@ plugins { apply from: rootProject.file( 'gradle/java-module.gradle' ) +apply from: rootProject.file( 'gradle/releasable.gradle' ) + apply plugin: 'org.hibernate.matrix-test' apply plugin: 'org.hibernate.orm.build.reports' @@ -65,6 +67,7 @@ dependencies { if ( project.ormVersion.isSnapshot ) { // only run the ci build tasks for SNAPSHOT versions task ciBuild( dependsOn: [clean, test] ) + tasks.release.enabled false } else { task release( dependsOn: [clean, test] ) diff --git a/gradle/java-module.gradle b/gradle/java-module.gradle index f689375e28..82c6da1798 100644 --- a/gradle/java-module.gradle +++ b/gradle/java-module.gradle @@ -14,7 +14,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'de.thetaphi:forbiddenapis:3.1' + classpath 'de.thetaphi:forbiddenapis:3.2' } } @@ -58,25 +58,6 @@ if ( !project.description ) { configurations.all { - resolutionStrategy { - dependencySubstitution { - // will handle dependencies pulled in transitively - substitute module( 'javax.persistence:javax.persistence-api' ) with module( libraries.jakarta_jpa ) - substitute module( 'javax.transaction:jta' ) with module( libraries.jakarta_jta ) - substitute module( 'org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec' ) with module( libraries.jakarta_jta ) - substitute module( 'javax.validation:validation-api' ) with module( libraries.jakarta_validation ) - substitute module( 'javax.interceptor:javax.interceptor-api' ) with module( libraries.jakarta_interceptor ) - substitute module( 'javax.activation:javax.activation-api' ) with module( libraries.jakarta_activation ) - substitute module( 'javax.enterprise:cdi-api' ) with module( libraries.jakarta_cdi ) - substitute module( 'org.jboss.weld.se:weld-se-shaded' ) with module( libraries.jakarta_weld ) - substitute module( 'javax.xml.bind:jaxb-api' ) with module( libraries.jakarta_jaxb_api ) - substitute module( 'org.glassfish.jaxb:jaxb-runtime' ) with module( libraries.jakarta_jaxb_runtime ) - substitute module( 'org.jboss.narayana.jta:narayana-jta' ) with module( libraries.jboss_jta_jakarta ) - substitute module( 'org.jboss:jboss-transaction-spi' ) with module( libraries.jboss_tx_spi_jakarta ) - substitute module( 'org.hibernate.validator:hibernate-validator' ) with module( libraries.jakarta_validator ) - substitute module( 'org.glassfish:javax.el' ) with module( libraries.jakarta_el ) - } - } exclude group: 'xml-apis', module: 'xml-apis' } @@ -147,6 +128,11 @@ dependencies { tasks.withType( JavaCompile ) { options.encoding = 'UTF-8' + options.warnings false +// javaCompileTask.options.compilerArgs += [ +// "-nowarn", +// "-encoding", "UTF-8" +// ] } if ( !gradle.ext.javaToolchainEnabled ) { @@ -186,20 +172,15 @@ else { } // Configure JVM Options - tasks.withType( JavaCompile ).configureEach { - options.forkOptions.jvmArgs.addAll( getProperty( 'toolchain.compiler.jvmargs' ).toString().split( ' ' ) ) - } - tasks.withType( Javadoc ).configureEach { - options.setJFlags( getProperty( 'toolchain.javadoc.jvmargs' ).toString().split( ' ' ).toList().findAll( { !it.isEmpty() } ) ) - } - // Display version of Java tools tasks.withType( JavaCompile ).configureEach { + options.forkOptions.jvmArgs.addAll( getProperty( 'toolchain.compiler.jvmargs' ).toString().split( ' ' ) ) doFirst { logger.lifecycle "Compiling with '${javaCompiler.get().metadata.installationPath}'" } } tasks.withType( Javadoc ).configureEach { + options.setJFlags( getProperty( 'toolchain.javadoc.jvmargs' ).toString().split( ' ' ).toList().findAll( { !it.isEmpty() } ) ) doFirst { logger.lifecycle "Generating javadoc with '${javadocTool.get().metadata.installationPath}'" } @@ -209,18 +190,6 @@ else { task compile(dependsOn: [compileJava, processResources, compileTestJava, processTestResources] ) -convention.findPlugin( JavaPluginConvention.class ).sourceSets.each { sourceSet -> - JavaCompile javaCompileTask = project.tasks.findByName( sourceSet.compileJavaTaskName ) as JavaCompile - - // NOTE : this aptDir stuff is needed until we can have IntelliJ run annotation processors for us - // which cannot happen until we can fold hibernate-testing back into hibernate-core/src/test - // which cannot happen until... ugh - - javaCompileTask.options.compilerArgs += [ - "-nowarn", - "-encoding", "UTF-8" - ] -} // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Attach tools JAR to the classpath for byteman tests diff --git a/gradle/module.gradle b/gradle/module.gradle index 64a624bab6..c5e644ff9c 100644 --- a/gradle/module.gradle +++ b/gradle/module.gradle @@ -1,4 +1,4 @@ -// Applied to all projects +// Applied to all modules (sub-projects) apply from: rootProject.file( 'gradle/base-information.gradle' ) diff --git a/gradle/published-java-module.gradle b/gradle/published-java-module.gradle index 608b5abb2a..81c4540212 100644 --- a/gradle/published-java-module.gradle +++ b/gradle/published-java-module.gradle @@ -5,10 +5,14 @@ * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -apply plugin: 'signing' +apply from: rootProject.file( 'gradle/releasable.gradle' ) apply from: rootProject.file( 'gradle/java-module.gradle' ) apply from: rootProject.file( 'gradle/publishing-pom.gradle' ) +apply plugin: 'signing' + +tasks.getByPath( ':release:publishReleaseArtifacts' ).dependsOn tasks.release + configurations { javadocSources { description 'Used to aggregate javadocs for the whole project' @@ -107,10 +111,12 @@ signing { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Release / publishing tasks -task ciBuild( dependsOn: [test, publish] ) +task ciBuild { + dependsOn test, publish +} -task release(dependsOn: [test, publishToSonatype]) -publishToSonatype.mustRunAfter test +tasks.release.dependsOn tasks.test, tasks.publishToSonatype +tasks.publishToSonatype.mustRunAfter test // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/gradle/releasable.gradle b/gradle/releasable.gradle new file mode 100644 index 0000000000..d350a0814e --- /dev/null +++ b/gradle/releasable.gradle @@ -0,0 +1,7 @@ +apply from: rootProject.file( 'gradle/base-information.gradle' ) + +task release { + dependsOn ':release:releaseChecks' + mustRunAfter ':release:releaseChecks' + enabled !project.ormVersion.isSnapshot +} diff --git a/release/release.gradle b/release/release.gradle index 2eb1fa89c6..fda46f30ef 100644 --- a/release/release.gradle +++ b/release/release.gradle @@ -554,16 +554,6 @@ task release { finalizedBy gitTasksAfterRelease } -rootProject.subprojects.each { Project subProject -> - if ( project.name != subProject.name ) { - if ( subProject.tasks.findByName( 'release' ) ) { - project.tasks.publishReleaseArtifacts.dependsOn( subProject.tasks.release ) - subProject.tasks.release.dependsOn( releaseChecks ) - subProject.tasks.release.mustRunAfter( releaseChecks ) - } - } -} - task ciReleaseChecks { dependsOn releaseChecks } @@ -716,7 +706,8 @@ class ReleaseNote { gradle.getTaskGraph().whenReady {tg-> - if ( tg.hasTask( project.tasks.releaseChecks ) ) { + if ( tg.hasTask( project.tasks.releaseChecks ) + && ! project.getGradle().getStartParameter().isDryRun() ) { String releaseVersionLocal String developmentVersionLocal diff --git a/tooling/hibernate-gradle-plugin/hibernate-gradle-plugin.gradle b/tooling/hibernate-gradle-plugin/hibernate-gradle-plugin.gradle index b74c0070b4..f7ac25d331 100644 --- a/tooling/hibernate-gradle-plugin/hibernate-gradle-plugin.gradle +++ b/tooling/hibernate-gradle-plugin/hibernate-gradle-plugin.gradle @@ -15,6 +15,7 @@ plugins { } apply from: rootProject.file( 'gradle/java-module.gradle' ) +apply from: rootProject.file( 'gradle/releasable.gradle' ) description = "Gradle plugin for integrating Hibernate aspects into your build" @@ -91,7 +92,7 @@ tasks.test { jvmArgs( ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] ) } -task release { +tasks.release { dependsOn tasks.publishPlugins } diff --git a/tooling/project-template/README.adoc b/tooling/project-template/README.adoc deleted file mode 100644 index ee9a399e11..0000000000 --- a/tooling/project-template/README.adoc +++ /dev/null @@ -1,6 +0,0 @@ -A template for projects wanting to use Hibernate ORM. - -Useful to either: - -1. Bootstrap a new user project -2. Bootstrap a test-case project diff --git a/tooling/project-template/project-template.gradle b/tooling/project-template/project-template.gradle deleted file mode 100644 index 455e6457a0..0000000000 --- a/tooling/project-template/project-template.gradle +++ /dev/null @@ -1,112 +0,0 @@ -import org.apache.tools.ant.filters.ReplaceTokens - -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -plugins { - id 'base' - - // for publishing snapshots - id 'maven-publish' - id 'org.hibernate.build.maven-repo-auth' - - // publishing to BinTray - id "com.jfrog.bintray" - id "nu.studer.credentials" version "2.1" -} - -// NOTE : Had trouble using the `distribution` plugin, so manually using Jar/Tar tasks - -apply from: rootProject.file( 'gradle/base-information.gradle' ) - -ext { - processedTemplateDir = project.layout.buildDirectory.dir('resources/template') - archiveDir = project.layout.buildDirectory.dir('distributions') -} - -task processTemplateResources(type:Copy) { - inputs.files( 'src/template/resources' ) - outputs.dir( processedTemplateDir ) - - description = 'Copies the template sources into the build dir, performing some replacements' - - from( 'src/template/resources' ) { - filter( ReplaceTokens, tokens: [ 'ormVersion' : project.version.toString() ] ) - } - into processedTemplateDir.get().asFile -} - -task templateTgz(type:Tar) { - description = 'Bundles the template project into a TGZ archive' - - inputs.files( processedTemplateDir ) - outputs.dir( archiveDir ) - - dependsOn project.tasks.processTemplateResources - - compression = Compression.GZIP - - from processedTemplateDir.get().asFile - - destinationDirectory = archiveDir -} - -task templateZip(type:Zip) { - description = 'Bundles the template project into a Zip archive' - - inputs.files( processedTemplateDir ) - outputs.dir( archiveDir ) - - dependsOn project.tasks.processTemplateResources - - from processedTemplateDir.get().asFile - - destinationDirectory = archiveDir -} - -bintray { - user = credentials.'personal.bintray.user' - key = credentials.'personal.bintray.key' - - filesSpec { - from templateTgz - from templateZip - } - - pkg { - userOrg = 'hibernate' - repo = 'generic' - name = 'orm-project-template' - } -} - -task assembleDist( dependsOn: [tasks.templateTgz, tasks.templateZip] ) -task release( dependsOn: tasks.assembleDist ) - -tasks.publish { - dependsOn tasks.assembleDist -} - -tasks.bintrayUpload { - dependsOn tasks.assembleDist - doFirst { - if ( credentials.'personal.bintray.user' == null ) { - throw new GradleException( "BinTray user not known, cannot perform upload" ); - } - if ( credentials.'personal.bintray.key' == null ) { - throw new GradleException( "BinTray API key not known, cannot perform upload" ); - } - } -} - -if ( version.toString().endsWith( "-SNAPSHOT" ) ) { - tasks.bintrayUpload.enabled = false - tasks.release.dependsOn tasks.publish -} -else { - tasks.publish.enabled = false - tasks.release.dependsOn tasks.bintrayUpload -} \ No newline at end of file diff --git a/tooling/project-template/src/template/resources/README.adoc b/tooling/project-template/src/template/resources/README.adoc deleted file mode 100644 index d447ebe99e..0000000000 --- a/tooling/project-template/src/template/resources/README.adoc +++ /dev/null @@ -1,5 +0,0 @@ -A template project to help bootstrap a Gradle project with support for Hibernate -specific extensions. - -This might be useful for new users wanting to get started as well as a quick way to -bootstrap project for test cases (bug reports, etc) diff --git a/tooling/project-template/src/template/resources/build.gradle.kts b/tooling/project-template/src/template/resources/build.gradle.kts deleted file mode 100644 index 71d782381e..0000000000 --- a/tooling/project-template/src/template/resources/build.gradle.kts +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ - -// ################################################################################### -// again, needed to be able to consume `org.hibernate.orm` plugin SNAPSHOTS -buildscript { - configurations { - classpath { - resolutionStrategy { - cacheChangingModulesFor(0, java.util.concurrent.TimeUnit.SECONDS ) - } - } - } -} -// ################################################################################### - - -plugins { - java - - // todo : find a way to inject this version - // - this is yet another example of where lazybones - // (or proper Gradle build-init feature) would be - // incredibly useful. Same with groupId, package-name, - // etc. - id( "org.hibernate.orm" ) version "@ormVersion@" -} - -group = "your.org" -version = "the-version" - -repositories { - mavenCentral() -} - -dependencies { - val ormVersion = "@ormVersion@" - val junit5Version = "5.3.1" - val h2Version = "1.4.199" - - implementation( "org.hibernate.orm", "hibernate-core", ormVersion ) - - testImplementation( "org.hibernate.orm", "hibernate-testing", ormVersion ) - testImplementation( "org.junit.jupiter", "junit-jupiter-api", junit5Version ) - testImplementation( "org.junit.jupiter", "junit-jupiter-params", junit5Version ) - - testRuntimeOnly( "org.junit.jupiter", "junit-jupiter-engine", junit5Version ) - testRuntimeOnly( "com.h2database", "h2", h2Version ) - testRuntimeOnly( "org.jboss.logging", "jboss-logging", "3.3.2.Final" ) - testRuntimeOnly( "log4j", "log4j", "1.2.17" ) -} - -hibernate { - enhancement { - // all false by default - lazyInitialization = true - dirtyTracking = true - } -} - -tasks { - test { - useJUnitPlatform() - } -} - -task( "compile" ) { - dependsOn( tasks.compileJava ) - dependsOn( tasks.compileTestJava ) - dependsOn( tasks.processResources ) - dependsOn( tasks.processTestResources ) -} - -configure { - sourceCompatibility = JavaVersion.VERSION_11 -} diff --git a/tooling/project-template/src/template/resources/settings.gradle.kts b/tooling/project-template/src/template/resources/settings.gradle.kts deleted file mode 100644 index edbb06527f..0000000000 --- a/tooling/project-template/src/template/resources/settings.gradle.kts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -rootProject.name = "my-hibernate-project" - -// ################################################################################### -// A lot of magic to be able to consumer SNAPSHOT versions of the Hibernate ORM plugin... -pluginManagement { - repositories { - gradlePluginPortal() - maven { - name = "jboss-snapshots-repository" - url = uri( "https://repository.jboss.org/nexus/content/repositories/snapshots" ) - } - } - - resolutionStrategy { - eachPlugin { - if ( requested.id.namespace == "org.hibernate" - && requested.id.name == "orm" - && requested.version.orEmpty().endsWith("-SNAPSHOT" ) ) { - val notation = "org.hibernate.orm:hibernate-gradle-plugin:${requested.version}" - logger.lifecycle( "Swapping SNAPSHOT version of plugin : {}", notation ) - useModule( notation ) - } - } - } -} -// ################################################################################### \ No newline at end of file diff --git a/tooling/project-template/src/template/resources/src/main/java/org/your/domain/SimpleEntity.java b/tooling/project-template/src/template/resources/src/main/java/org/your/domain/SimpleEntity.java deleted file mode 100644 index f97493db5c..0000000000 --- a/tooling/project-template/src/template/resources/src/main/java/org/your/domain/SimpleEntity.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.your.domain; - -import javax.persistence.Entity; -import javax.persistence.Id; - -/** - * A simple example entity - */ -@Entity -public class SimpleEntity { - @Id - private Integer id; - private String name; - - private SimpleEntity() { - } - - public SimpleEntity(Integer id) { - this.id = id; - } - - public SimpleEntity(Integer id, String name) { - this.id = id; - this.name = name; - } - - public Integer getId() { - return id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/tooling/project-template/src/template/resources/src/test/java/org/your/domain/EntityTests.java b/tooling/project-template/src/template/resources/src/test/java/org/your/domain/EntityTests.java deleted file mode 100644 index 004bbd937b..0000000000 --- a/tooling/project-template/src/template/resources/src/test/java/org/your/domain/EntityTests.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.your.domain; - -import org.hibernate.testing.orm.junit.DomainModel; -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.SessionFactory; -import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static com.arjuna.ats.internal.jdbc.recovery.JDBCXARecovery.PASSWORD; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hibernate.cfg.AvailableSettings.URL; -import static org.hibernate.cfg.AvailableSettings.USER; - -/** - * Tests for SimpleEntity - */ -@ServiceRegistry( - settings = { - // can define settings here, or in `hibernate.properties` file - @Setting( name = URL, value = "jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000" ), - @Setting( name = USER, value = "sa" ), - @Setting( name = PASSWORD, value = "" ) - } -) -@DomainModel( annotatedClasses = SimpleEntity.class ) -@SessionFactory() -public class EntityTests { - @Test - public void basicTest(SessionFactoryScope scope) { - scope.inTransaction( - session -> { - final SimpleEntity entity = session.createQuery( "from SimpleEntity", SimpleEntity.class ).uniqueResult(); - assertThat( entity, notNullValue() ); - } - ); - } - - @BeforeEach - public void createTestData(SessionFactoryScope scope) { - scope.inTransaction( - session -> session.persist( new SimpleEntity( 1, "the first" ) ) - ); - } - - @BeforeEach - public void dropTestData(SessionFactoryScope scope) { - scope.inTransaction( - session -> session.createQuery( "delete SimpleEntity" ).executeUpdate() - ); - } -} diff --git a/tooling/project-template/src/template/resources/src/test/resources/log4j.properties b/tooling/project-template/src/template/resources/src/test/resources/log4j.properties deleted file mode 100644 index 9863d25fbe..0000000000 --- a/tooling/project-template/src/template/resources/src/test/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.rootLogger=warn, stdout -log4j.logger.org.hibernate=info \ No newline at end of file