Skip to content

Commit 192d705

Browse files
DavideDSanne
authored andcommitted
[#1686] Clean up hibernate-reactive-core build.gradle
Remove warnings and refactor the createion of the test tasks
1 parent f8407d6 commit 192d705

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

hibernate-reactive-core/build.gradle

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ dependencies {
4949
testRuntimeOnly "com.microsoft.sqlserver:mssql-jdbc:12.2.0.jre11"
5050

5151
// JDBC driver for Testcontainers with MariaDB Server
52-
testRuntimeOnly "org.mariadb.jdbc:mariadb-java-client:3.1.4";
52+
testRuntimeOnly "org.mariadb.jdbc:mariadb-java-client:3.1.4"
5353

5454
// JDBC driver for Testcontainers with MYSQL Server
55-
testRuntimeOnly "com.mysql:mysql-connector-j:8.0.33";
55+
testRuntimeOnly "com.mysql:mysql-connector-j:8.0.33"
5656

5757
// JDBC driver for Db2 server, for testing
5858
testRuntimeOnly "com.ibm.db2:jcc:11.5.8.0"
@@ -78,10 +78,6 @@ dependencies {
7878
testImplementation "org.testcontainers:oracle-xe:${testcontainersVersion}"
7979
}
8080

81-
test {
82-
useJUnitPlatform()
83-
}
84-
8581
// Print a summary of the results of the tests (number of failures, successes and skipped)
8682
def loggingSummary(db, result, desc) {
8783
if ( !desc.parent ) { // will match the outermost suite
@@ -91,38 +87,52 @@ def loggingSummary(db, result, desc) {
9187
}
9288
}
9389

90+
// Example:
91+
// gradle test -Pdb=MySQL
92+
test {
93+
def selectedDb = project.hasProperty( 'db' )
94+
? project.properties['db']
95+
: 'PostgreSQL'
96+
doFirst {
97+
systemProperty 'db', selectedDb
98+
}
99+
afterSuite { desc, result ->
100+
loggingSummary( selectedDb, result, desc )
101+
}
102+
}
103+
94104
// Configuration for the tests
95-
tasks.withType(Test) {
105+
tasks.withType( Test ).configureEach {
96106
defaultCharacterEncoding = "UTF-8"
107+
useJUnitPlatform()
97108
testLogging {
98-
displayGranularity 1
99109
showStandardStreams = project.hasProperty('showStandardOutput')
100110
showStackTraces = true
101111
exceptionFormat = 'full'
102-
events 'PASSED', 'FAILED', 'SKIPPED'
112+
displayGranularity = 1
113+
events = ['PASSED', 'FAILED', 'SKIPPED']
103114
}
104115
systemProperty 'docker', project.hasProperty( 'docker' ) ? 'true' : 'false'
105116
systemProperty 'org.hibernate.reactive.common.InternalStateAssertions.ENFORCE', 'true'
106117

107118
if ( project.hasProperty( 'includeTests' ) ) {
108119
// Example: ./gradlew testAll -PincludeTests=DefaultPortTest
109120
filter {
110-
includeTestsMatching project.getProperty( 'includeTests' ) ?: '*'
121+
includeTestsMatching project.properties['includeTests'] ?: '*' as String
111122
}
112123
}
113124
}
114125

115-
// Example:
116-
// gradle test -Pdb=MySQL
117-
test {
118-
def selectedDb = project.hasProperty( 'db' )
119-
? project.getProperty( 'db' )
120-
: 'PostgreSQL'
121-
afterSuite { desc, result ->
122-
loggingSummary( selectedDb, result, desc )
123-
}
124-
doFirst {
125-
systemProperty 'db', selectedDb
126+
def createTestDbTask(dbName) {
127+
tasks.register( "testDb${dbName}", Test ) {
128+
description = "Run tests for ${dbName}"
129+
130+
doFirst() {
131+
systemProperty 'db', dbName
132+
}
133+
afterSuite { desc, result ->
134+
loggingSummary( dbName, result, desc )
135+
}
126136
}
127137
}
128138

@@ -132,22 +142,16 @@ test {
132142
// gradle testDbMySQL testDbDB2
133143
tasks.addRule( "Pattern testDb<id>" ) { String taskName ->
134144
if ( taskName.startsWith( "testDb" ) ) {
135-
task( type: Test, taskName ) {
136-
def dbName = taskName.substring( "testDb".length() )
137-
description = "Run tests for ${dbName}"
138-
139-
afterSuite { desc, result ->
140-
loggingSummary( dbName, result, desc )
141-
}
142-
doFirst() {
143-
systemProperty 'db', dbName
144-
}
145-
}
145+
def dbName = taskName.substring( "testDb".length() )
146+
createTestDbTask( dbName )
146147
}
147148
}
148149

149150
// The dbs we want to test when running testAll
150151
def dbs = ['MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle']
151-
task testAll( dependsOn: dbs.collect( [] as HashSet ) { db -> "testDb${db}" } ) {
152+
dbs.forEach { createTestDbTask it }
153+
154+
tasks.register( "testAll", Test ) {
152155
description = "Run tests for ${dbs}"
156+
dependsOn = dbs.collect( [] as HashSet ) { db -> "testDb${db}" }
153157
}

0 commit comments

Comments
 (0)