-
Notifications
You must be signed in to change notification settings - Fork 46
/
build.gradle
112 lines (96 loc) · 2.92 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'org.hibernate.build.gradle:gradle-maven-publish-auth:2.0.1'
classpath 'org.hibernate.build.gradle:gradle-animalSniffer-plugin:1.0.1.Final'
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.25.0"
classpath 'nu.studer:gradle-credentials-plugin:2.2'
}
}
plugins {
id 'java-library'
id 'maven-publish'
id 'nu.studer.credentials' version '2.1'
id 'idea'
id 'eclipse'
}
repositories {
mavenCentral()
}
apply from: rootProject.file( 'gradle/base-information.gradle' )
apply from: rootProject.file( 'gradle/publishing.gradle' )
apply plugin: 'com.diffplug.spotless'
dependencies {
testImplementation 'junit:junit:3.8.1'
}
wrapper {
distributionType = Wrapper.DistributionType.ALL
}
spotless {
//Don't fail during the check: rather than enforcing guidelines, we use this plugin to fix mistakes automatically.
enforceCheck false
java {
licenseHeaderFile 'spotless.license.java'
removeUnusedImports()
importOrder()
trimTrailingWhitespace()
endWithNewline()
}
}
tasks.compileJava.dependsOn(spotlessApply)
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
// Main binaries use a Java 11 baseline
compileJava {
sourceCompatibility = 11
targetCompatibility = 11
}
// ... and we want to test against that
compileTestJava {
sourceCompatibility = 11
targetCompatibility = 11
}
// Some tests require Java 17
if ( !JavaVersion.current().isCompatibleWith( JavaVersion.VERSION_17 ) ) {
throw new IllegalStateException("Building this project requires JDK 17 (produced binaries will still target Java 11).")
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
// We add a new source set, which contains tests that can run on JDK17+
sourceSets {
testJava17 {
java {
srcDirs = ['src/test/java17']
}
}
}
// For the new source set, we need to configure the source and target version to 17
compileTestJava17Java {
sourceCompatibility = 17
targetCompatibility = 17
}
// The source set gets a custom configuration which extends the normal test implementation config
configurations {
testJava17Implementation.extendsFrom(testImplementation, testRuntimeOnly)
testJava17CompileOnly.extendsFrom(testCompileOnly)
}
// Add the output from src/main/java as dependency
dependencies {
testJava17Implementation files(sourceSets.main.output.classesDirs) {
builtBy compileJava
}
}
// We execute the Java 17 tests in a custom test task
task testJava17(type: Test) {
testClassesDirs = sourceSets.testJava17.output.classesDirs
classpath = sourceSets.testJava17.runtimeClasspath
}
testClasses.dependsOn compileTestJava17Java
// And run this as part of the check task by default
check.dependsOn testJava17