2018-01-10 16:06:58 -05:00
/ *
* 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
* /
2018-05-12 21:29:50 -04:00
2018-01-10 16:06:58 -05:00
/ * *
* Support for modules that contain Java code
* /
2018-05-12 21:29:50 -04:00
buildscript {
repositories {
mavenCentral ( )
}
dependencies {
2024-08-07 07:52:12 -04:00
classpath buildscriptLibs . forbiddenapis
2018-05-12 21:29:50 -04:00
}
}
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis
2019-05-21 17:29:57 -04:00
import org.apache.tools.ant.filters.ReplaceTokens
2023-08-29 14:19:06 -04:00
apply plugin: 'java-library'
2022-03-15 10:39:07 -04:00
apply from: rootProject . file ( 'gradle/module.gradle' )
2018-01-10 16:06:58 -05:00
apply from: rootProject . file ( 'gradle/databases.gradle' )
2023-08-29 14:19:06 -04:00
apply from: rootProject . file ( 'gradle/javadoc.gradle' )
2018-01-10 16:06:58 -05:00
2022-10-24 05:00:44 -04:00
apply plugin: 'biz.aQute.bnd.builder'
2021-06-26 09:46:09 -04:00
apply plugin: 'org.hibernate.orm.database-service'
2023-08-07 21:05:47 -04:00
apply plugin: 'org.hibernate.orm.build.java-module'
2018-01-10 16:06:58 -05:00
2023-04-05 07:59:39 -04:00
apply plugin: 'org.checkerframework'
2024-07-18 20:43:48 -04:00
apply plugin: 'de.thetaphi.forbiddenapis'
2024-09-14 13:10:26 -04:00
apply plugin: 'com.diffplug.spotless'
2023-04-05 07:59:39 -04:00
2024-03-14 16:00:56 -04:00
apply plugin: "jacoco"
2018-01-10 16:06:58 -05:00
apply plugin: 'build-dashboard'
apply plugin: 'project-report'
2021-05-14 15:59:59 -04:00
2020-04-16 06:03:49 -04:00
// Attempt to leverage JetBrain's Gradle extension to automatically define
2019-05-21 17:29:57 -04:00
// `copyResourcesToIntelliJOutFolder` as a "build trigger" on import.
//
// However, see https://github.com/JetBrains/gradle-idea-ext-plugin/issues/8
apply plugin: 'org.jetbrains.gradle.plugin.idea-ext'
2018-01-10 16:06:58 -05:00
ext {
java9ModuleNameBase = project . name . startsWith ( 'hibernate-' ) ? name . drop ( 'hibernate-' . length ( ) ) : name
2022-05-24 05:53:26 -04:00
java9ModuleName = "org.hibernate.orm.$project.java9ModuleNameBase" . replace ( '-' , '.' )
2018-10-15 05:56:27 -04:00
forbiddenAPITargetJDKCompatibility = '11'
2018-01-10 16:06:58 -05:00
}
2020-04-06 13:21:11 -04:00
if ( ! project . description ) {
project . description = "The Hibernate ORM $project.name module"
2018-01-10 16:06:58 -05:00
}
2023-09-06 10:27:12 -04:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Reproducible Builds
// https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives
// Configure archive tasks to produce reproducible archives:
tasks . withType ( AbstractArchiveTask ) . configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
2018-01-10 16:06:58 -05:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Configurations and Dependencies
2023-08-29 14:19:06 -04:00
configurations . configureEach {
resolutionStrategy . eachDependency { details - >
//Force the "byte buddy agent" version to match the Byte Buddy version
// we use, as Mockito might pull in a mismatched version transitively
if ( details . requested . group = = "net.bytebuddy" & & details . requested . name = = 'byte-buddy-agent' ) {
details . useVersion libs . versions . byteBuddy . get ( )
}
}
}
2022-04-22 19:40:06 -04:00
2018-01-10 16:06:58 -05:00
dependencies {
2022-04-22 19:40:06 -04:00
implementation libs . logging
2019-05-21 17:29:57 -04:00
2022-04-22 19:40:06 -04:00
compileOnly libs . loggingAnnotations
2022-11-24 07:41:59 -05:00
// Used for compiling some Oracle specific JdbcTypes
2024-12-01 07:37:51 -05:00
compileOnly jdbcLibs . oracle
2019-05-21 17:29:57 -04:00
// JUnit dependencies made up of:
// * JUnit 5
// * the Jupiter engine which runs JUnit 5 based tests
// * the "vintage" engine - which runs JUnit 3 and 4 based tests
2022-04-22 19:40:06 -04:00
testImplementation testLibs . junit5Api
testImplementation testLibs . junit5Engine
testImplementation testLibs . junit5Params
testImplementation testLibs . junit4
testImplementation testLibs . junit4Engine
testImplementation testLibs . assertjCore
2019-05-21 17:29:57 -04:00
2022-04-22 19:40:06 -04:00
testRuntimeOnly testLibs . log4j2
testRuntimeOnly libs . byteBuddy
2018-01-10 16:06:58 -05:00
//Databases
2024-12-01 07:37:51 -05:00
testRuntimeOnly jdbcLibs . h2
testRuntimeOnly jdbcLibs . derby
testRuntimeOnly jdbcLibs . derbyTools
testRuntimeOnly jdbcLibs . hsqldb
testRuntimeOnly jdbcLibs . postgresql
testRuntimeOnly jdbcLibs . mssql
testRuntimeOnly jdbcLibs . informix
testRuntimeOnly jdbcLibs . cockroachdb
testRuntimeOnly jdbcLibs . sybase
2023-04-24 15:35:51 -04:00
testRuntimeOnly rootProject . fileTree ( dir: 'drivers' , include: '*.jar' )
2021-02-03 04:55:07 -05:00
// Since both the DB2 driver and HANA have a package "net.jpountz" we have to add dependencies conditionally
// This is due to the "no split-packages" requirement of Java 9+
if ( db . startsWith ( 'db2' ) ) {
2024-12-01 07:37:51 -05:00
testRuntimeOnly jdbcLibs . db2
2018-01-10 16:06:58 -05:00
}
2021-02-03 04:55:07 -05:00
else if ( db . startsWith ( 'hana' ) ) {
2024-12-01 07:37:51 -05:00
testRuntimeOnly jdbcLibs . hana
2018-01-10 16:06:58 -05:00
}
2022-04-06 12:52:56 -04:00
else if ( db . startsWith ( 'mysql' ) | | db . startsWith ( 'tidb' ) ) {
2024-12-01 07:37:51 -05:00
testRuntimeOnly jdbcLibs . mysql
2022-04-06 12:52:56 -04:00
}
else if ( db . startsWith ( 'mariadb' ) ) {
2024-12-01 07:37:51 -05:00
testRuntimeOnly jdbcLibs . mariadb
2022-04-06 12:52:56 -04:00
}
2022-12-05 06:29:48 -05:00
else if ( db . startsWith ( 'firebird' ) ) {
2024-12-01 07:37:51 -05:00
testRuntimeOnly jdbcLibs . firebird
2022-12-05 06:29:48 -05:00
}
2023-10-02 09:19:12 -04:00
else if ( db . startsWith ( 'oracle' ) ) {
2024-12-01 07:37:51 -05:00
testRuntimeOnly jdbcLibs . oracle
testRuntimeOnly jdbcLibs . oracleXml
testRuntimeOnly jdbcLibs . oracleXmlParser
2023-10-02 09:19:12 -04:00
}
2023-11-13 21:24:17 -05:00
else if ( db . startsWith ( 'altibase' ) ) {
2024-12-01 07:37:51 -05:00
testRuntimeOnly jdbcLibs . altibase
2023-11-13 21:24:17 -05:00
}
2024-06-07 08:51:13 -04:00
else if ( db . startsWith ( 'informix' ) ) {
2024-12-01 07:37:51 -05:00
testRuntimeOnly jdbcLibs . informix
2024-06-07 08:51:13 -04:00
}
2018-01-10 16:06:58 -05:00
2022-04-22 19:40:06 -04:00
annotationProcessor libs . loggingProcessor
annotationProcessor libs . logging
annotationProcessor libs . loggingAnnotations
2022-01-11 16:47:13 -05:00
constraints {
implementation ( 'org.apache.logging.log4j:log4j-core' ) {
version {
2022-01-12 09:37:16 -05:00
strictly ( '[2.17.1, 3[' )
prefer ( '2.17.1' )
2022-01-11 16:47:13 -05:00
}
2022-01-12 09:37:16 -05:00
because ( 'CVE-2021-44228, CVE-2021-45046, CVE-2021-45105, CVE-2021-44832: Log4j vulnerable to remote code execution and other critical security vulnerabilities' )
2022-01-11 16:47:13 -05:00
}
}
2018-01-10 16:06:58 -05:00
}
2022-03-15 21:10:17 -04:00
configurations {
javadocSources {
canBeConsumed = true
canBeResolved = false
visible = false
description = 'Configuration for accessing the sources that should be included in the javadoc for the project'
}
}
artifacts {
sourceSets . main . allJava . srcDirs . each { srcDir - >
javadocSources srcDir
}
}
2018-01-10 16:06:58 -05:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Compilation
2019-10-21 05:02:11 -04:00
tasks . withType ( JavaCompile ) {
2018-01-10 16:06:58 -05:00
options . encoding = 'UTF-8'
2022-03-15 13:15:56 -04:00
options . warnings false
2023-10-13 08:23:54 -04:00
options . fork = true
options . forkOptions . memoryMaximumSize = '768m'
2024-08-10 16:03:13 -04:00
options . compilerArgs + = [
// disable adding @Generated annotation in the logger impls to make
// the logging annotation processor create the same sources each time.
"-Aorg.jboss.logging.tools.addGeneratedAnnotation=false"
2022-03-15 13:15:56 -04:00
// "-nowarn",
// "-encoding", "UTF-8"
2024-08-10 16:03:13 -04:00
]
2019-10-21 05:02:11 -04:00
}
2024-09-14 13:10:26 -04:00
tasks . compileJava . dependsOn spotlessApply
2022-04-22 19:40:06 -04:00
2018-01-10 16:06:58 -05:00
task compile ( dependsOn: [ compileJava , processResources , compileTestJava , processTestResources ] )
2021-08-02 17:35:16 -04:00
2018-01-10 16:06:58 -05:00
2021-09-29 12:50:55 -04:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Attach tools JAR to the classpath for byteman tests
final File toolsJar = file ( "${System.getProperty('java.home')}/../lib/tools.jar" )
if ( toolsJar . exists ( ) ) {
dependencies {
2021-10-13 04:24:56 -04:00
testImplementation files ( toolsJar )
2021-09-29 12:50:55 -04:00
}
}
2018-01-10 16:06:58 -05:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Testing
2021-08-26 12:36:51 -04:00
class HeapDumpPathProvider implements CommandLineArgumentProvider {
2021-09-23 16:01:29 -04:00
@OutputDirectory
Provider < Directory > path
2021-08-26 12:36:51 -04:00
@Override
Iterable < String > asArguments ( ) {
[ "-XX:HeapDumpPath=${path.get().asFile.absolutePath}" ]
}
}
2020-11-09 04:13:34 -05:00
2019-05-21 17:29:57 -04:00
tasks . withType ( Test . class ) . each { test - >
test . useJUnitPlatform ( )
2021-06-26 09:46:09 -04:00
test . usesService ( project . gradle . sharedServices . registrations . getByName ( 'databaseService' ) . service )
2021-11-26 11:24:34 -05:00
// Byteman needs this property to be set, https://developer.jboss.org/thread/274997
test . jvmArgs + = [ "-Djdk.attach.allowAttachSelf=true" ]
2021-08-26 12:36:51 -04:00
test . jvmArgumentProviders . add (
2021-09-23 16:01:29 -04:00
new HeapDumpPathProvider ( path: project . layout . buildDirectory . dir ( "OOM-dump" ) )
2021-08-26 12:36:51 -04:00
)
2019-05-21 17:29:57 -04:00
test . jvmArgs + = [
2018-01-10 16:06:58 -05:00
'-XX:+HeapDumpOnOutOfMemoryError' ,
2020-10-25 17:57:55 -04:00
'-XX:MetaspaceSize=256M'
2018-01-10 16:06:58 -05:00
]
2020-10-27 10:24:37 -04:00
test . maxHeapSize = '3G'
2018-01-10 16:06:58 -05:00
2019-05-21 17:29:57 -04:00
test . systemProperties [ 'hibernate.test.validatefailureexpected' ] = true
2023-05-10 17:59:46 -04:00
test . systemProperties [ 'hibernate.highlight_sql' ] = false
2019-05-21 17:29:57 -04:00
test . systemProperties + = System . properties . findAll { it . key . startsWith ( "hibernate." ) }
test . enableAssertions = true
2020-04-16 06:03:49 -04:00
2019-05-21 17:29:57 -04:00
if ( project . name ! = 'hibernate-testing' ) {
test . dependsOn ':hibernate-testing:test'
}
2022-09-19 08:51:06 -04:00
// Allow to exclude specific tests
if ( project . hasProperty ( 'excludeTests' ) ) {
test . filter {
excludeTestsMatching project . property ( 'excludeTests' ) . toString ( )
}
}
2018-01-10 16:06:58 -05:00
}
2019-05-21 17:29:57 -04:00
sourceSets {
test {
resources {
configure ( srcDir ( 'src/test/resources' ) ) {
filter {
include '*.properties'
include '*.xml'
include '**/*.properties'
include '**/*.xml'
}
2018-01-10 16:06:58 -05:00
}
}
}
}
2019-05-21 17:29:57 -04:00
processTestResources {
2021-10-13 04:24:56 -04:00
duplicatesStrategy DuplicatesStrategy . INCLUDE
2019-05-21 17:29:57 -04:00
inputs . property ( "db" , db )
2022-10-19 13:25:16 -04:00
inputs . property ( "dbHost" , dbHost )
2023-12-21 12:05:44 -05:00
inputs . file ( rootProject . file ( "gradle/databases.gradle" ) )
2021-09-29 12:50:55 -04:00
doLast {
copy {
from ( sourceSets . test . java . srcDirs ) {
include '**/*.properties'
include '**/*.xml'
}
2021-12-01 12:50:10 -05:00
into sourceSets . test . java . classesDirectory
2021-09-29 12:50:55 -04:00
}
copy {
from file ( 'src/test/resources' )
into file ( "${buildDir}/resources/test" )
exclude 'src/test/resources/hibernate.properties'
}
copy {
from file ( 'src/test/resources/hibernate.properties' )
into file ( "${buildDir}/resources/test" )
filter ( ReplaceTokens , tokens: dbBundle [ db ] )
}
}
2019-02-18 09:14:24 -05:00
}
2020-05-27 12:22:54 -04:00
// Keep system properties in sync with gradle.properties!
test {
systemProperty 'user.language' , 'en'
systemProperty 'user.country' , 'US'
systemProperty 'user.timezone' , 'UTC'
systemProperty 'file.encoding' , 'UTF-8'
2021-02-09 07:03:18 -05:00
// Needed for AdoptOpenJDK on alpine? The problem is similar to this: https://github.com/mockito/mockito/issues/978
jvmArgs '-XX:+StartAttachListener'
2020-05-27 12:22:54 -04:00
}
2019-05-27 07:02:38 -04:00
test {
2019-06-13 02:44:53 -04:00
if ( project . findProperty ( 'log-test-progress' ) ? . toString ( ) ? . toBoolean ( ) ) {
// Log a statement for each test.
// Used in the Travis build so that Travis doesn't end up panicking because there's no output for a long time.
testLogging {
events "passed" , "skipped" , "failed"
2023-05-08 05:29:32 -04:00
exceptionFormat = 'full'
2019-06-13 02:44:53 -04:00
}
2019-05-27 07:02:38 -04:00
}
}
2021-05-18 17:03:34 -04:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Jar
jar {
manifest {
attributes (
// Basic JAR manifest attributes
'Specification-Title' : project . name ,
'Specification-Version' : project . version ,
'Specification-Vendor' : 'Hibernate.org' ,
'Implementation-Title' : project . name ,
'Implementation-Version' : project . version ,
'Implementation-Vendor' : 'Hibernate.org' ,
'Implementation-Vendor-Id' : 'org.hibernate' ,
2021-06-07 06:47:53 -04:00
'Implementation-Url' : 'https://hibernate.org/orm' ,
2021-05-18 17:03:34 -04:00
// Java 9 module name
'Automatic-Module-Name' : project . java9ModuleName ,
// Hibernate-specific JAR manifest attributes
'Hibernate-VersionFamily' : project . ormVersion . family ,
'Hibernate-JpaVersion' : project . jpaVersion . name ,
// BND Plugin instructions (for OSGi):
2021-07-26 14:51:22 -04:00
'-reproducible' : true ,
'-noextraheaders' : true ,
2021-05-18 17:03:34 -04:00
'Bundle-Name' : project . name ,
'Bundle-SymbolicName' : project . java9ModuleName ,
'Bundle-Vendor' : 'Hibernate.org' ,
2021-06-07 06:47:53 -04:00
'Bundle-DocURL' : "https://www.hibernate.org/orm/${project.ormVersion.family}" ,
2021-05-18 17:03:34 -04:00
// This is overridden in some sub-projects
'Import-Package' : [
// Temporarily support JTA 1.1 -- Karaf and other frameworks still
// use it. Without this, the plugin generates [1.2,2).
'javax.transaction;version="[1.1,2)"' ,
// Also import every package referenced in the code
// (note that '*' is resolved at build time to a list of packages)
'*'
] . join ( ',' ) ,
'-exportcontents' : "*;version=${project.version}"
)
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// sources
task sourcesJar ( type: Jar ) {
from project . sourceSets . main . allSource
manifest {
attributes (
// Basic JAR manifest attributes
'Specification-Title' : project . name ,
'Specification-Version' : project . version ,
'Specification-Vendor' : 'Hibernate.org' ,
'Implementation-Title' : project . name ,
'Implementation-Version' : project . version ,
'Implementation-Vendor' : 'Hibernate.org' ,
'Implementation-Vendor-Id' : 'org.hibernate' ,
2021-06-07 06:47:53 -04:00
'Implementation-Url' : 'https://hibernate.org/orm' ,
2021-05-18 17:03:34 -04:00
// Hibernate-specific JAR manifest attributes
'Hibernate-VersionFamily' : project . ormVersion . family ,
'Hibernate-JpaVersion' : project . jpaVersion . name
)
}
archiveClassifier . set ( 'sources' )
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Javadoc
2023-08-29 14:19:06 -04:00
tasks . named ( "javadoc" , Javadoc ) {
configure ( options ) {
windowTitle = "Hibernate Javadocs ($project.name)"
docTitle = "Hibernate Javadocs ($project.name : $project.version)"
}
}
2021-05-18 17:03:34 -04:00
2018-01-10 16:06:58 -05:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// IDE
/ *
2021-06-26 09:46:09 -04:00
The latest versions of IntelliJ copy the test resources into out /test/ resources and
use those for its test classpath . Unfortunately , this occurs before the placeholder
in the test config file are substituted with the testing values .
2018-01-10 16:06:58 -05:00
This behaviour prevents the execution of the hibernate tests from inside the IDE .
A solution is to enable the 'After Build' Execution of the copyResourcesToIntelliJOutFolder task
from the 'Gradle project' IntelliJ tool window ( The task can be found under hibernate - orm > Task > other )
* /
2019-05-21 17:29:57 -04:00
task copyResourcesToIntelliJOutFolder ( type: Task , dependsOn: project . tasks . processTestResources ) {
2018-01-10 16:06:58 -05:00
doLast {
copy {
from "$buildDir/resources/test"
into 'out/test/resources'
}
}
}
2021-06-26 09:46:09 -04:00
2018-01-10 16:06:58 -05:00
2018-06-01 01:56:13 -04:00
/ *
Use this task to set the current DB in a given module .
> gradlew sDB - Pdb = mysql
Afterward , you can run any test from the IDE against that particular DB .
* /
2020-09-01 05:31:22 -04:00
task setDataBase dependsOn ( processTestResources , copyResourcesToIntelliJOutFolder ) {
2022-03-15 21:10:17 -04:00
println ( "Setting current database to ${db}" )
2018-06-01 01:56:13 -04:00
}
2018-01-10 16:06:58 -05:00
2022-03-15 21:10:17 -04:00
tasks . copyResourcesToIntelliJOutFolder . mustRunAfter processTestResources
2020-09-01 05:31:22 -04:00
2018-01-10 16:06:58 -05:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Report configs
2024-10-30 12:02:58 -04:00
tasks . register ( 'enforceRules' ) {
2024-09-27 03:48:08 -04:00
doLast {
def illegalImport = ~ /^import (sun|java.awt|org.slf4j)/
def missingNewline = ~ /^\s*}\s*(else|catch|finally)/
def lowerEll = ~ /\b\d+l\b/
2024-09-30 12:11:20 -04:00
def equals = ~ /boolean +equals\((@?\w+ )*Object \w+\)/
def hashCode = ~ /int +hashCode\(\)/
2024-09-27 03:48:08 -04:00
def errors = 0
def tree = fileTree ( "src/main/java/" )
tree . include "**/*.java"
tree . each { file - >
def lineNum = 0
def shortName = file . path . substring ( rootDir . path . length ( ) )
2024-09-30 12:11:20 -04:00
def equalsMinusHashcode = 0
2024-09-27 03:48:08 -04:00
file . eachLine { line - >
lineNum + +
if ( line = ~ illegalImport ) {
errors + +
logger . error ( "Illegal import in ${shortName}\n${lineNum}: ${line}" )
}
if ( line = ~ missingNewline ) {
errors + +
logger . error ( "Missing newline in ${shortName}\n${lineNum}: ${line}" )
}
if ( line = ~ lowerEll ) {
errors + +
logger . error ( "Lowercase long literal in ${shortName}\n${lineNum}: ${line}" )
}
2024-09-30 12:11:20 -04:00
if ( ! line . startsWith ( "//" ) ) { //ignore commented-out code
if ( line = ~ equals ) {
equalsMinusHashcode + +
}
if ( line = ~ hashCode ) {
equalsMinusHashcode - -
}
}
}
if ( equalsMinusHashcode > 0 ) {
errors + +
logger . error ( "Equals with missing hash code in ${shortName}" )
}
if ( equalsMinusHashcode < 0 ) {
errors + +
logger . error ( "Hash code with missing equals in ${shortName}" )
2024-09-27 03:48:08 -04:00
}
}
if ( errors > 0 ) {
throw new GradleException ( "Code rules were violated ($errors problems)" )
}
}
2018-01-10 16:06:58 -05:00
}
2024-09-14 13:10:26 -04:00
spotless {
//Don't fail during the check: rather than enforcing guidelines, we use this plugin to fix mistakes automatically.
enforceCheck false
java {
2024-09-17 07:47:59 -04:00
targetExclude ( "**/target/**/*.java" )
licenseHeaderFile rootProject . file ( 'spotless.license.java' )
2024-09-14 13:10:26 -04:00
removeUnusedImports ( )
2024-09-17 07:47:59 -04:00
indentWithTabs ( 4 )
2024-09-14 13:10:26 -04:00
trimTrailingWhitespace ( )
endWithNewline ( )
}
}
2024-10-30 12:02:58 -04:00
tasks . check . dependsOn enforceRules
2024-09-27 03:48:08 -04:00
2024-10-30 12:02:58 -04:00
tasks . register ( "ciCheck" ) {
// Task used by CI builds
group "verification"
description "Checks for CI environments"
dependsOn tasks . check
2024-11-13 10:43:34 -05:00
}
2024-10-30 12:02:58 -04:00
2024-11-13 10:43:34 -05:00
gradle . taskGraph . whenReady {
if ( it . hasTask ( tasks . ciCheck ) ) {
// These are already enforced by the formatChecks task
tasks . spotlessApply . enabled = false
tasks . spotlessJavaApply . enabled = false
tasks . enforceRules . enabled = false
2024-10-30 12:02:58 -04:00
}
}
tasks . register ( "formatChecks" ) {
// Only runs static code analysis, doesn't require compilation
group "verification"
description "Code style and formatting checks"
dependsOn tasks . spotlessCheck
dependsOn tasks . enforceRules
}
2024-09-14 13:10:26 -04:00
2023-07-04 04:53:27 -04:00
class CompilerStubsArgumentProvider implements CommandLineArgumentProvider {
@InputDirectory
@PathSensitive ( PathSensitivity . NONE )
File stubsDir
@Override
Iterable < String > asArguments ( ) {
{ return [ "-Astubs=${stubsDir}" ] }
}
}
tasks . withType ( JavaCompile ) . configureEach { task - >
// stubs argument needs to be passed as an absolute path, JavaCompile uses the Worker API which changes the current
// working directory and prevents from using a relative path to locate a project file.
// Using a CommandLineArgumentProvider allows build cache hits when the build cache is relocated.
task . options . compilerArgumentProviders . add ( new CompilerStubsArgumentProvider ( stubsDir: new File ( project . rootDir , "checkerstubs" ) ) )
2024-06-11 10:15:58 -04:00
if ( System . getProperty ( 'APT_DEBUG' , 'false' ) = = 'true' ) {
task . options . forkOptions . jvmArgs + = [ '-Xdebug' , '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9099' ]
}
2023-07-04 04:53:27 -04:00
}
2023-04-05 07:59:39 -04:00
checkerFramework {
2024-06-11 10:19:06 -04:00
excludeTests = true
2023-04-05 07:59:39 -04:00
checkers = [
'org.checkerframework.checker.nullness.NullnessChecker'
]
extraJavacArgs = [
2023-07-04 04:53:27 -04:00
'-AsuppressWarnings=initialization' ,
// stubs is passed directly through options.compilerArgumentProviders
2024-03-01 16:09:04 -05:00
'-AonlyDefs=^org\\.hibernate\\.(jdbc|exception|integrator|processor|service|spi|pretty|property\\.access|stat|engine\\.(config|jndi|profile|spi|transaction)|(action|context|bytecode)\\.spi)\\.'
2023-04-05 07:59:39 -04:00
]
}
2024-07-18 20:43:48 -04:00
tasks . forbiddenApisMain {
// unfortunately we currently have many uses of default Locale implicitly (~370)
// which need to be fixed before we can enable the "unsafe" check
//bundledSignatures += ["jdk-system-out", "jdk-non-portable", "jdk-unsafe-${jdkVersions.baseline}"]
bundledSignatures + = [ "jdk-system-out" , "jdk-non-portable" ]
2020-04-16 06:46:19 -04:00
2024-07-18 20:43:48 -04:00
suppressAnnotations + = [
"org.hibernate.internal.build.AllowSysOut" ,
"org.hibernate.internal.build.AllowPrintStacktrace" ,
"org.hibernate.internal.build.AllowNonPortable"
]
2022-03-15 21:10:17 -04:00
}
2022-03-15 17:24:07 -04:00
2024-07-18 20:43:48 -04:00
tasks . forbiddenApisTest {
enabled = false
2021-06-26 09:46:09 -04:00
}
2020-04-16 06:46:19 -04:00