|
| 1 | +import org.gradle.api.tasks.testing.logging.TestExceptionFormat |
| 2 | +import org.gradle.jvm.tasks.Jar |
| 3 | + |
| 4 | +plugins { |
| 5 | + `java-library` |
| 6 | + `maven-publish` |
| 7 | +} |
| 8 | + |
| 9 | +repositories { |
| 10 | + mavenCentral() |
| 11 | +} |
| 12 | + |
| 13 | +val javacExports = listOf( |
| 14 | + "jdk.compiler/com.sun.tools.javac.api", |
| 15 | + "jdk.compiler/com.sun.tools.javac.code", |
| 16 | + "jdk.compiler/com.sun.tools.javac.tree", |
| 17 | + "jdk.compiler/com.sun.tools.javac.util", |
| 18 | +) |
| 19 | + |
| 20 | +val java8Compiler = javaToolchains.compilerFor { |
| 21 | + languageVersion = JavaLanguageVersion.of(8) |
| 22 | +} |
| 23 | + |
| 24 | +dependencies { |
| 25 | + compileOnly(files(java8Compiler.map { it.metadata.installationPath.file("lib/tools.jar") })) |
| 26 | + testImplementation(libs.junit.jupiter) |
| 27 | + testRuntimeOnly("org.junit.platform:junit-platform-launcher") |
| 28 | +} |
| 29 | + |
| 30 | +java { |
| 31 | + toolchain { |
| 32 | + languageVersion = JavaLanguageVersion.of(17) |
| 33 | + } |
| 34 | + withSourcesJar() |
| 35 | +} |
| 36 | + |
| 37 | +tasks.named<JavaCompile>("compileJava") { |
| 38 | + javaCompiler = java8Compiler |
| 39 | + sourceCompatibility = JavaVersion.VERSION_1_8.toString() |
| 40 | + targetCompatibility = JavaVersion.VERSION_1_8.toString() |
| 41 | +} |
| 42 | + |
| 43 | +tasks.named<JavaCompile>("compileTestJava") { |
| 44 | + sourceCompatibility = JavaVersion.VERSION_17.toString() |
| 45 | + targetCompatibility = JavaVersion.VERSION_17.toString() |
| 46 | +} |
| 47 | + |
| 48 | +tasks.withType<Test>().configureEach { |
| 49 | + useJUnitPlatform() |
| 50 | + jvmArgs(javacExports.map { export -> "--add-exports=$export=ALL-UNNAMED" }) |
| 51 | + testLogging { |
| 52 | + exceptionFormat = TestExceptionFormat.FULL |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +tasks.named<Jar>("jar") { |
| 57 | + manifest { |
| 58 | + attributes["Automatic-Module-Name"] = "net.ikvm.javarefplugin" |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +publishing { |
| 63 | + publications { |
| 64 | + create<MavenPublication>("mavenJava") { |
| 65 | + from(components["java"]) |
| 66 | + artifactId = rootProject.name |
| 67 | + pom { |
| 68 | + name = "java-ref-plugin" |
| 69 | + description = project.description.toString() |
| 70 | + url = "https://github.com/ikvmnet/java-ref-plugin" |
| 71 | + licenses { |
| 72 | + license { |
| 73 | + name = "MIT License" |
| 74 | + url = "https://opensource.org/licenses/MIT" |
| 75 | + } |
| 76 | + } |
| 77 | + developers { |
| 78 | + developer { |
| 79 | + id = "ikvmnet" |
| 80 | + name = "IKVM" |
| 81 | + } |
| 82 | + } |
| 83 | + scm { |
| 84 | + connection = "scm:git:https://github.com/ikvmnet/java-ref-plugin.git" |
| 85 | + developerConnection = "scm:git:ssh://git@github.com/ikvmnet/java-ref-plugin.git" |
| 86 | + url = "https://github.com/ikvmnet/java-ref-plugin" |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + repositories { |
| 92 | + maven { |
| 93 | + name = "GitHubPackages" |
| 94 | + val repositoryPath = providers.environmentVariable("GITHUB_REPOSITORY") |
| 95 | + .orElse("ikvmnet/java-ref-plugin") |
| 96 | + url = uri("https://maven.pkg.github.com/${repositoryPath.get()}") |
| 97 | + credentials { |
| 98 | + username = providers.gradleProperty("githubUsername") |
| 99 | + .orElse(providers.environmentVariable("GITHUB_ACTOR")) |
| 100 | + .orNull |
| 101 | + password = providers.gradleProperty("githubToken") |
| 102 | + .orElse(providers.environmentVariable("GITHUB_TOKEN")) |
| 103 | + .orNull |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | +} |
0 commit comments