-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle.kts
89 lines (78 loc) · 2.9 KB
/
build.gradle.kts
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
/*
* This file is part of ProxyAuth - https://github.com/Zeckie/ProxyAuth
* ProxyAuth is Copyright (c) 2021 Zeckie
*
* ProxyAuth is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* ProxyAuth is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with ProxyAuth. If you have the source code, this is in a file called
* LICENSE. If you have the built jar file, the licence can be viewed by
* running "java -jar ProxyAuth-<version>.jar licence".
* Otherwise, see <https://www.gnu.org/licenses/>.
*/
import java.util.regex.Matcher
import java.util.regex.Pattern
plugins {
java
id("org.jetbrains.changelog") version "1.3.1"
}
repositories {
mavenCentral()
}
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
}
tasks.withType<Test> {
useJUnitPlatform() // JUnit 5
}
version = "0.1.1"
group = "com.github.zeckie"
/*
* Work out current java version
* Note: versions prior to JEP223 (Java 9) had version numbers starting with "1." so
* will be counted as major version 1.
*/
@Suppress("PropertyName") // IDEA doesn't recognise MIN_JAVA_VER as a constant
val MIN_JAVA_VER = 9
val fullVersion: String = System.getProperty("java.version")
val matchMajor: Matcher = Pattern.compile("^\\d+").matcher(fullVersion)
val majorVersion = if (matchMajor.find()) Integer.parseInt(matchMajor.group()) else 0
if (majorVersion < MIN_JAVA_VER) {
println("Using java toolchain, as java version ($fullVersion) is less than minimum ($MIN_JAVA_VER)")
java.toolchain.languageVersion.set(JavaLanguageVersion.of(MIN_JAVA_VER))
} else {
if (majorVersion > 9) {
// Compile for minimum supported java version
// skip for java 9 due to https://bugs.openjdk.java.net/browse/JDK-8139607
tasks.withType<JavaCompile> {
options.release.set(MIN_JAVA_VER)
}
}
// Test on minimum supported java version
tasks.register<Test>("testsMinJava") {
description = "Run test suite with ${project.name}'s minimum supported java version ($MIN_JAVA_VER). " +
"Checks that the code is compatible with, and compiled with the correct options to be run on that version"
group = "verification"
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(MIN_JAVA_VER))
})
}
tasks.check {
dependsOn("testsMinJava")
}
}
// set main class
tasks.jar {
manifest.attributes["Main-Class"] = "proxyauth.Main"
}
changelog {
groups.set(listOf("Added"))
}