├── tests ├── gradle ├── gradlew ├── jvm │ ├── gradle │ ├── gradlew │ ├── src │ │ └── main │ │ │ └── kotlin │ │ │ └── hello.kt │ ├── settings.gradle.kts │ └── build.gradle.kts ├── kmp │ ├── gradle │ ├── gradlew │ ├── src │ │ ├── commonMain │ │ │ └── kotlin │ │ │ │ └── hello.kt │ │ ├── jvmAndMacos │ │ │ └── kotlin │ │ │ │ └── hello2.kt │ │ └── jvmMain │ │ │ └── kotlin │ │ │ └── hello3.kt │ ├── gradle.properties │ ├── settings.gradle.kts │ └── build.gradle.kts ├── agp9-kmp │ ├── gradle │ ├── gradlew │ ├── src │ │ ├── commonMain │ │ │ └── kotlin │ │ │ │ └── MainKotlin.kt │ │ └── androidMain │ │ │ └── kotlin │ │ │ └── Android.kt │ ├── settings.gradle.kts │ └── build.gradle.kts ├── java │ ├── gradle │ ├── gradlew │ ├── settings.gradle.kts │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── Main.java │ └── build.gradle.kts ├── wasm-js │ ├── gradle │ ├── gradlew │ ├── src │ │ ├── wasmJsTest │ │ │ └── kotlin │ │ │ │ └── MainTest.kt │ │ └── wasmJsMain │ │ │ └── kotlin │ │ │ └── hello.kt │ ├── settings.gradle.kts │ └── build.gradle.kts ├── agp8-java │ ├── gradle │ ├── gradlew │ ├── gradle.properties │ ├── src │ │ ├── foo │ │ │ └── java │ │ │ │ └── Foo.java │ │ └── main │ │ │ └── java │ │ │ └── Main.java │ ├── settings.gradle.kts │ └── build.gradle.kts ├── agp8-kotlin │ ├── gradle │ ├── gradlew │ ├── gradle.properties │ ├── src │ │ └── main │ │ │ ├── kotlin │ │ │ └── MainKotlin.kt │ │ │ └── java │ │ │ └── JavaMain.java │ ├── settings.gradle.kts │ └── build.gradle.kts ├── agp9-kotlin │ ├── gradle │ ├── gradlew │ ├── gradle.properties │ ├── src │ │ └── main │ │ │ ├── kotlin │ │ │ └── MainKotlin.kt │ │ │ └── java │ │ │ └── JavaMain.java │ ├── settings.gradle.kts │ └── build.gradle.kts ├── build-logic │ ├── gradle │ ├── gradlew │ ├── settings.gradle.kts │ ├── build.gradle.kts │ └── src │ │ └── main │ │ └── kotlin │ │ └── check-publication.kt └── gradle-plugin │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── src │ └── main │ │ └── kotlin │ │ └── MainPlugin.kt │ ├── settings.gradle.kts │ ├── build.gradle.kts │ ├── gradlew.bat │ └── gradlew ├── tapmoc-gradle-plugin ├── testProjects │ ├── check-dependencies │ │ ├── gradle │ │ ├── src │ │ │ └── main │ │ │ │ └── kotlin │ │ │ │ └── hello.kt │ │ ├── settings.gradle.kts │ │ └── build.gradle.kts │ ├── kotlin-higher-version │ │ ├── src │ │ │ └── main │ │ │ │ └── kotlin │ │ │ │ └── Main.kt │ │ ├── settings.gradle.kts │ │ └── build.gradle.kts │ ├── java │ │ ├── Hello.java │ │ ├── settings.gradle.kts │ │ ├── src │ │ │ └── main │ │ │ │ └── java │ │ │ │ └── Main.java │ │ └── build.gradle.kts │ └── java-meta-inf │ │ ├── settings.gradle.kts │ │ └── build.gradle.kts ├── src │ ├── agp │ │ └── kotlin │ │ │ └── tapmoc │ │ │ └── internal │ │ │ ├── Agp.kt │ │ │ └── AgpImpl.kt │ ├── kgp │ │ └── kotlin │ │ │ └── tapmoc │ │ │ └── internal │ │ │ ├── Kgp.kt │ │ │ └── KgpImpl.kt │ ├── main │ │ └── kotlin │ │ │ └── tapmoc │ │ │ ├── TapmocPlugin.kt │ │ │ ├── compatibility.kt │ │ │ ├── TapmocExtension.kt │ │ │ └── internal │ │ │ └── TapmocExtensionImpl.kt │ └── test │ │ └── kotlin │ │ └── Tests.kt ├── api │ └── tapmoc-gradle-plugin.api └── build.gradle.kts ├── gradle ├── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties └── libs.versions.toml ├── gradle.properties ├── .idea ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml └── dictionaries │ └── project.xml ├── .github └── workflows │ ├── build-pull-request.yaml │ ├── publish-snapshot.yaml │ └── publish-release.yaml ├── librarian.root.properties ├── scripts ├── integration-tests.sh └── update-repo.main.kts ├── .gitignore ├── .editorconfig ├── settings.gradle.kts ├── tapmoc-tasks ├── build.gradle.kts ├── api │ └── tapmoc-tasks.api └── src │ └── main │ └── kotlin │ └── tapmoc │ └── task │ ├── checkKotlinStdlibVersions.kt │ ├── checkKotlinMetadataVersions.kt │ └── checkClassFileVersions.kt ├── LICENSE ├── gradlew.bat ├── README.md ├── CHANGELOG.md └── gradlew /tests/gradle: -------------------------------------------------------------------------------- 1 | ../gradle -------------------------------------------------------------------------------- /tests/gradlew: -------------------------------------------------------------------------------- 1 | ../gradlew -------------------------------------------------------------------------------- /tests/jvm/gradle: -------------------------------------------------------------------------------- 1 | ../../gradle -------------------------------------------------------------------------------- /tests/kmp/gradle: -------------------------------------------------------------------------------- 1 | ../../gradle -------------------------------------------------------------------------------- /tests/agp9-kmp/gradle: -------------------------------------------------------------------------------- 1 | ../../gradle -------------------------------------------------------------------------------- /tests/java/gradle: -------------------------------------------------------------------------------- 1 | ../../gradle -------------------------------------------------------------------------------- /tests/java/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /tests/jvm/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /tests/kmp/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /tests/wasm-js/gradle: -------------------------------------------------------------------------------- 1 | ../../gradle -------------------------------------------------------------------------------- /tests/agp8-java/gradle: -------------------------------------------------------------------------------- 1 | ../../gradle -------------------------------------------------------------------------------- /tests/agp8-java/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /tests/agp8-kotlin/gradle: -------------------------------------------------------------------------------- 1 | ../../gradle -------------------------------------------------------------------------------- /tests/agp8-kotlin/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /tests/agp9-kmp/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /tests/agp9-kotlin/gradle: -------------------------------------------------------------------------------- 1 | ../../gradle -------------------------------------------------------------------------------- /tests/agp9-kotlin/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /tests/build-logic/gradle: -------------------------------------------------------------------------------- 1 | ../../gradle -------------------------------------------------------------------------------- /tests/build-logic/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /tests/wasm-js/gradlew: -------------------------------------------------------------------------------- 1 | ../../gradlew -------------------------------------------------------------------------------- /tests/jvm/src/main/kotlin/hello.kt: -------------------------------------------------------------------------------- 1 | val hello = "Hello" 2 | -------------------------------------------------------------------------------- /tests/agp8-java/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4g 2 | -------------------------------------------------------------------------------- /tests/agp8-kotlin/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4g 2 | -------------------------------------------------------------------------------- /tests/agp9-kotlin/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4g 2 | -------------------------------------------------------------------------------- /tests/kmp/src/commonMain/kotlin/hello.kt: -------------------------------------------------------------------------------- 1 | val hello = "Hello" 2 | -------------------------------------------------------------------------------- /tests/kmp/src/jvmAndMacos/kotlin/hello2.kt: -------------------------------------------------------------------------------- 1 | val hello2 = "Hello2" 2 | -------------------------------------------------------------------------------- /tests/kmp/src/jvmMain/kotlin/hello3.kt: -------------------------------------------------------------------------------- 1 | val hello3 = "Hello3" 2 | -------------------------------------------------------------------------------- /tests/agp8-kotlin/src/main/kotlin/MainKotlin.kt: -------------------------------------------------------------------------------- 1 | val hello = "hello" 2 | -------------------------------------------------------------------------------- /tests/agp9-kotlin/src/main/kotlin/MainKotlin.kt: -------------------------------------------------------------------------------- 1 | val hello = "hello" 2 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/check-dependencies/gradle: -------------------------------------------------------------------------------- 1 | ../../../gradle -------------------------------------------------------------------------------- /tests/agp9-kmp/src/commonMain/kotlin/MainKotlin.kt: -------------------------------------------------------------------------------- 1 | val hello = "hello" 2 | -------------------------------------------------------------------------------- /tests/gradle-plugin/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.unsafe.suppress-gradle-api=true 2 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/check-dependencies/src/main/kotlin/hello.kt: -------------------------------------------------------------------------------- 1 | val hello = "world" -------------------------------------------------------------------------------- /tests/agp9-kmp/src/androidMain/kotlin/Android.kt: -------------------------------------------------------------------------------- 1 | fun foo() { 2 | mutableListOf("").removeFirst() 3 | } 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GradleUp/Tapmoc/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /tests/kmp/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4g 2 | org.gradle.caching=true 3 | org.gradle.parallel=true 4 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/kotlin-higher-version/src/main/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | fun main() { 2 | println("Hello world!") 3 | } 4 | -------------------------------------------------------------------------------- /tests/wasm-js/src/wasmJsTest/kotlin/MainTest.kt: -------------------------------------------------------------------------------- 1 | import kotlin.test.Test 2 | 3 | class MainTest { 4 | @Test 5 | fun test() { 6 | 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/gradle-plugin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GradleUp/Tapmoc/HEAD/tests/gradle-plugin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/java/Hello.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | public class Hello { 4 | public static String world = "Hello World"; 5 | } 6 | -------------------------------------------------------------------------------- /tests/agp8-kotlin/src/main/java/JavaMain.java: -------------------------------------------------------------------------------- 1 | public class JavaMain { 2 | public static void main(String[] args) { 3 | System.out.println("Hello world"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/agp9-kotlin/src/main/java/JavaMain.java: -------------------------------------------------------------------------------- 1 | public class JavaMain { 2 | public static void main(String[] args) { 3 | System.out.println("Hello world"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx4g 2 | org.gradle.caching=true 3 | org.gradle.configuration-cache=true 4 | org.gradle.configuration-cache.parallel=true 5 | org.gradle.parallel=true 6 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/src/agp/kotlin/tapmoc/internal/Agp.kt: -------------------------------------------------------------------------------- 1 | package tapmoc.internal 2 | 3 | import org.gradle.api.JavaVersion 4 | 5 | internal interface Agp { 6 | fun javaCompatibility(javaVersion: JavaVersion) 7 | } 8 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/java/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | it.maven("../../../build/m2") 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/java/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | } 5 | } 6 | 7 | includeBuild("../../") 8 | includeBuild("../build-logic") 9 | -------------------------------------------------------------------------------- /tests/jvm/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | } 5 | } 6 | 7 | includeBuild("../../") 8 | includeBuild("../build-logic") 9 | -------------------------------------------------------------------------------- /tests/kmp/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | } 5 | } 6 | 7 | includeBuild("../../") 8 | includeBuild("../build-logic") 9 | -------------------------------------------------------------------------------- /tests/wasm-js/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | } 5 | } 6 | 7 | includeBuild("../../") 8 | includeBuild("../build-logic") 9 | -------------------------------------------------------------------------------- /.idea/dictionaries/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | lifecyle 5 | patrouille 6 | tapmoc 7 | 8 | 9 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/java-meta-inf/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | it.maven("../../../build/m2") 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/check-dependencies/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | it.maven("../../../build/m2") 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/kotlin-higher-version/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | it.maven("../../../build/m2") 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/gradle-plugin/src/main/kotlin/MainPlugin.kt: -------------------------------------------------------------------------------- 1 | import org.gradle.api.Plugin 2 | import org.gradle.api.Project 3 | 4 | open class MainPlugin : Plugin { 5 | override fun apply(target: Project?) { 6 | TODO("Not yet implemented") 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tests/gradle-plugin/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | it.gradlePluginPortal() 5 | } 6 | } 7 | 8 | includeBuild("../../") 9 | includeBuild("../build-logic") 10 | -------------------------------------------------------------------------------- /tests/agp8-java/src/foo/java/Foo.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | class Foo { 4 | void main() { 5 | ArrayList list = new ArrayList(); 6 | list.add("foo"); 7 | // Uncommenting this should fail to compile 8 | // list.removeFirst(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/src/kgp/kotlin/tapmoc/internal/Kgp.kt: -------------------------------------------------------------------------------- 1 | package tapmoc.internal 2 | 3 | import org.gradle.api.Project 4 | 5 | internal interface Kgp { 6 | fun javaCompatibility(version: Int) 7 | fun kotlinCompatibility(version: String) 8 | fun version(project: Project): String 9 | } 10 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /.github/workflows/build-pull-request.yaml: -------------------------------------------------------------------------------- 1 | on: pull_request 2 | 3 | jobs: 4 | build-pull-request: 5 | runs-on: ubuntu-latest 6 | 7 | steps: 8 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2 9 | - run: ./gradlew build 10 | - run: ./scripts/integration-tests.sh 11 | -------------------------------------------------------------------------------- /tests/agp8-java/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | ArrayList list = new ArrayList(); 6 | list.add("foo"); 7 | // This is in android.jar so it compiles fine 8 | list.removeFirst(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/java/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | public class Main { 3 | public static void main(String[] args) { 4 | 5 | ArrayList list = new ArrayList(); 6 | list.add("foo"); 7 | // This must fail to compile because it's not in JDK 11 8 | // list.removeFirst(); 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/agp8-java/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | it.google() 5 | } 6 | } 7 | 8 | includeBuild("../../") 9 | includeBuild("../build-logic") 10 | 11 | fun toto(settings: Settings) { 12 | settings.layout.rootDirectory.files() 13 | } 14 | -------------------------------------------------------------------------------- /tests/agp9-kmp/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | it.google() 5 | } 6 | } 7 | 8 | includeBuild("../../") 9 | includeBuild("../build-logic") 10 | 11 | fun toto(settings: Settings) { 12 | settings.layout.rootDirectory.files() 13 | } 14 | -------------------------------------------------------------------------------- /tests/agp9-kotlin/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | it.google() 5 | } 6 | } 7 | 8 | includeBuild("../../") 9 | includeBuild("../build-logic") 10 | 11 | fun toto(settings: Settings) { 12 | settings.layout.rootDirectory.files() 13 | } 14 | -------------------------------------------------------------------------------- /librarian.root.properties: -------------------------------------------------------------------------------- 1 | java.compatibility=11 2 | kotlin.compatibility=2.0.21 3 | 4 | kdoc.olderVersions= 5 | 6 | pom.groupId=com.gradleup.tapmoc 7 | pom.version=0.3.3-SNAPSHOT 8 | pom.description=tapmoc 9 | pom.vcsUrl=https://github.com/GradleUp/tapmoc 10 | pom.developer=tapmoc authors 11 | pom.license=MIT 12 | 13 | gcs.bucket=gradleup 14 | gcs.prefix=m2 15 | -------------------------------------------------------------------------------- /tests/java/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.gradleup.tapmoc") 3 | id("check.publication") 4 | } 5 | 6 | tapmoc { 7 | java(11) 8 | kotlin("2.0.0") // This should be a no-op 9 | } 10 | 11 | checkPublication { 12 | jvmTarget.set(11) 13 | } 14 | 15 | // Testing that we are robust to plugins being added after the fact 16 | pluginManager.apply("java") 17 | -------------------------------------------------------------------------------- /tests/gradle-plugin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | # See https://github.com/gradle/gradle/pull/34540 4 | distributionUrl=https://services.gradle.org/distributions-snapshots/gradle-9.4.0-20251215022449+0000-bin.zip 5 | networkTimeout=10000 6 | validateDistributionUrl=true 7 | zipStoreBase=GRADLE_USER_HOME 8 | zipStorePath=wrapper/dists 9 | -------------------------------------------------------------------------------- /scripts/integration-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | set -e 3 | set -x 4 | cd tests/agp8-java && ./gradlew build 5 | cd ../agp8-kotlin && ./gradlew build 6 | cd ../agp9-kmp && ./gradlew build 7 | cd ../agp9-kotlin && ./gradlew build 8 | cd ../java && ./gradlew build 9 | cd ../jvm && ./gradlew build 10 | cd ../wasm-js && ./gradlew build 11 | cd ../gradle-plugin && ./gradlew build 12 | cd ../kmp && ./gradlew build 13 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/java/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | import com.example.Hello; 2 | 3 | import java.util.ArrayList; 4 | public class Main { 5 | public static void main(String[] args) { 6 | 7 | ArrayList list = new ArrayList(); 8 | list.add("foo"); 9 | // This must fail to compile because it's not in JDK 11 10 | // list.removeFirst(); 11 | 12 | System.out.println(Hello.world); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/jvm/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.gradleup.tapmoc") 3 | id("org.jetbrains.kotlin.jvm").version("2.2.0").apply(false) 4 | id("check.publication") 5 | id("maven-publish") 6 | } 7 | 8 | tapmoc { 9 | java(11) 10 | kotlin("1.9.0") 11 | checkDependencies() 12 | } 13 | 14 | checkPublication { 15 | jvmTarget.set(11) 16 | kotlinMetadataVersion.set("1.9.0") 17 | } 18 | 19 | pluginManager.apply("org.jetbrains.kotlin.jvm") 20 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/src/main/kotlin/tapmoc/TapmocPlugin.kt: -------------------------------------------------------------------------------- 1 | package tapmoc 2 | 3 | import tapmoc.internal.TapmocExtensionImpl 4 | import gratatouille.wiring.GPlugin 5 | import org.gradle.api.Project 6 | 7 | @GPlugin(id = "com.gradleup.tapmoc") 8 | internal fun tapmocPlugin(target: Project) { 9 | target.extensions.create( 10 | TapmocExtension::class.java, 11 | "tapmoc", 12 | TapmocExtensionImpl::class.java, 13 | target, 14 | ) 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .kotlin 2 | .fleet 3 | .gradle 4 | *.bak 5 | 6 | # Build outputs 7 | build 8 | 9 | # Idea 10 | **/.idea/* 11 | !**/.idea/codeStyles 12 | !**/.idea/icon.png 13 | !**/.idea/runConfigurations 14 | !**/.idea/scopes 15 | !**/.idea/dictionaries 16 | *.iml 17 | 18 | # Place where the Android SDK path is set 19 | local.properties 20 | 21 | # XCode 22 | xcuserdata 23 | project.xcworkspace 24 | 25 | # Mac OS Finder 26 | .DS_Store 27 | Thumbs.db 28 | 29 | -------------------------------------------------------------------------------- /tests/gradle-plugin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.gradleup.tapmoc") 3 | `embedded-kotlin` 4 | id("check.publication") 5 | id("java-gradle-plugin") 6 | } 7 | 8 | tapmoc { 9 | // Gradle 8.3 uses Kotlin 1.9 10 | java(11) 11 | kotlin("1.9.0") 12 | checkDependencies() 13 | } 14 | 15 | checkPublication { 16 | jvmTarget.set(11) 17 | kotlinMetadataVersion.set("1.9.0") 18 | } 19 | 20 | dependencies { 21 | compileOnlyApi("dev.gradleplugins:gradle-api:8.3") 22 | } 23 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/kotlin-higher-version/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import tapmoc.Severity 2 | 3 | buildscript { 4 | dependencies { 5 | classpath("com.gradleup.tapmoc:tapmoc-gradle-plugin:PLACEHOLDER") 6 | } 7 | } 8 | 9 | plugins { 10 | id("org.jetbrains.kotlin.jvm").version("2.2.0") 11 | } 12 | 13 | pluginManager.apply("com.gradleup.tapmoc") 14 | 15 | extensions.getByType(tapmoc.TapmocExtension::class.java).apply { 16 | java(8) 17 | kotlin("2.3.0") // This should make an error 18 | } 19 | -------------------------------------------------------------------------------- /scripts/update-repo.main.kts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env kotlin 2 | 3 | @file:Repository("https://repo.maven.apache.org/maven2/") 4 | @file:Repository("https://storage.googleapis.com/gradleup/m2") 5 | @file:Repository("https://jitpack.io") 6 | @file:DependsOn("com.gradleup.librarian:librarian-cli:0.1.1-SNAPSHOT-41af255deeb3b644524aed9ffe4c64aad5ebbd0b") 7 | 8 | import com.gradleup.librarian.cli.updateRepo 9 | 10 | updateRepo(args) { 11 | file("README.md") { 12 | replacePluginVersion("com.gradleup.tapmoc") 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/java-meta-inf/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import tapmoc.Severity 2 | 3 | buildscript { 4 | dependencies { 5 | classpath("com.gradleup.tapmoc:tapmoc-gradle-plugin:PLACEHOLDER") 6 | } 7 | } 8 | 9 | plugins { 10 | id("java") 11 | } 12 | 13 | pluginManager.apply("com.gradleup.tapmoc") 14 | extensions.getByType(tapmoc.TapmocExtension::class.java).apply { 15 | java(8) 16 | checkDependencies(Severity.ERROR) 17 | } 18 | 19 | dependencies { 20 | implementation("com.squareup.okhttp3:okhttp-jvm:5.3.2") 21 | } 22 | -------------------------------------------------------------------------------- /tests/build-logic/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | it.maven("https://storage.googleapis.com/gradleup/m2") { 5 | content { 6 | includeModule("com.gradleup.gratatouille", "gratatouille-processor") 7 | } 8 | } 9 | } 10 | repositories { 11 | maven("https://storage.googleapis.com/gradleup/m2") { 12 | content { 13 | includeGroupByRegex("com\\.gradleup\\..*") 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/wasm-js/build.gradle.kts: -------------------------------------------------------------------------------- 1 | @file:OptIn(ExperimentalWasmDsl::class) 2 | 3 | import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl 4 | 5 | plugins { 6 | alias(libs.plugins.kgp.multiplatform) 7 | id("com.gradleup.tapmoc") 8 | } 9 | 10 | tapmoc { 11 | java(11) 12 | kotlin("2.0.0") 13 | checkDependencies() 14 | } 15 | 16 | kotlin { 17 | jvm() 18 | wasmJs { 19 | nodejs() 20 | binaries.executable() 21 | } 22 | 23 | sourceSets { 24 | getByName("commonTest").dependencies { 25 | implementation(kotlin("test")) 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/agp8-kotlin/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.mavenCentral() 4 | it.google { 5 | content { 6 | includeGroupByRegex("com\\.google.*") 7 | includeGroupByRegex("com\\.android.*") 8 | includeGroupByRegex("androidx.*") 9 | } 10 | } 11 | it.gradlePluginPortal { 12 | content { 13 | includeGroupByRegex("org\\.gradle\\.kotlin.*") 14 | } 15 | } 16 | } 17 | } 18 | 19 | includeBuild("../../") 20 | includeBuild("../build-logic") 21 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_size = 2 6 | indent_style = space 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | 10 | [*.{kt,kts}] 11 | ij_kotlin_imports_layout = * 12 | ij_kotlin_allow_trailing_comma = true 13 | ij_kotlin_allow_trailing_comma_on_call_site = true 14 | ij_kotlin_line_break_after_multiline_when_entry = false 15 | ij_kotlin_name_count_to_use_star_import = 999 16 | ij_kotlin_name_count_to_use_star_import_for_members = 999 17 | ij_kotlin_packages_to_use_import_on_demand = unset 18 | indent_size = 2 19 | 20 | [*.md] 21 | trim_trailing_whitespace = false 22 | -------------------------------------------------------------------------------- /tests/wasm-js/src/wasmJsMain/kotlin/hello.kt: -------------------------------------------------------------------------------- 1 | interface Foo 2 | 3 | /** 4 | * This fails compilation with the error below if not using the correct kotlin-stdlib 5 | * 6 | * java.lang.IllegalStateException: Class "kotlin.wasm.internal.KClassInterfaceImpl" not found! Please make sure that your stdlib version is the same as the compiler. 7 | * at org.jetbrains.kotlin.backend.wasm.WasmSymbols.getIrClass(WasmSymbols.kt:446) 8 | * at org.jetbrains.kotlin.backend.wasm.WasmSymbols.getInternalClass(WasmSymbols.kt:450) 9 | * at org.jetbrains.kotlin.backend.wasm.WasmSymbols.access$getInternalClass(WasmSymbols.kt:33) 10 | */ 11 | fun main() { 12 | println(Foo::class.simpleName) 13 | } 14 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 18 | -------------------------------------------------------------------------------- /.github/workflows/publish-snapshot.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: [ main ] 4 | 5 | jobs: 6 | publish-snapshot: 7 | runs-on: ubuntu-latest 8 | if: github.event.repository.fork == false 9 | 10 | steps: 11 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2 12 | - run: | 13 | LIBRARIAN_VERSION_SHA1=$GITHUB_SHA ./gradlew librarianPublishToGcs 14 | ./gradlew librarianPublishToSnapshots 15 | env: 16 | LIBRARIAN_SONATYPE_PASSWORD: ${{ secrets.CENTRAL_PORTAL_PASSWORD }} 17 | LIBRARIAN_SONATYPE_USERNAME: ${{ secrets.CENTRAL_PORTAL_USERNAME }} 18 | LIBRARIAN_GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }} 19 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | listOf(repositories, dependencyResolutionManagement.repositories).forEach { 3 | it.apply { 4 | mavenCentral() 5 | google() 6 | maven("https://storage.googleapis.com/gradleup/m2") { 7 | content { 8 | includeModule("com.gradleup.gratatouille", "gratatouille-processor") 9 | includeModule("com.gradleup.nmcp", "nmcp-tasks") 10 | } 11 | } 12 | } 13 | } 14 | repositories { 15 | maven("https://storage.googleapis.com/gradleup/m2") { 16 | content { 17 | includeGroupByRegex("com\\.gradleup\\..*") 18 | } 19 | } 20 | } 21 | } 22 | 23 | include(":tapmoc-gradle-plugin") 24 | include(":tapmoc-tasks") 25 | -------------------------------------------------------------------------------- /tests/kmp/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.gradleup.tapmoc") 3 | id("org.jetbrains.kotlin.multiplatform").version("2.3.0") 4 | id("check.publication") 5 | } 6 | 7 | tapmoc { 8 | java(11) 9 | kotlin("2.0.0") 10 | checkDependencies() 11 | } 12 | 13 | kotlin { 14 | jvm() 15 | macosArm64() 16 | js { 17 | browser() 18 | } 19 | 20 | applyDefaultHierarchyTemplate() 21 | 22 | sourceSets { 23 | val jvmAndMacos by creating { 24 | dependsOn(commonMain.get()) 25 | } 26 | 27 | macosArm64Main.get().dependsOn(jvmAndMacos) 28 | jvmMain.get().dependsOn(jvmAndMacos) 29 | } 30 | } 31 | 32 | checkPublication { 33 | jvmTarget.set(11) 34 | kotlinMetadataVersion.set("2.0.0") 35 | } 36 | -------------------------------------------------------------------------------- /.github/workflows/publish-release.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | tags: 4 | - '*' 5 | 6 | jobs: 7 | publish-release: 8 | runs-on: ubuntu-latest 9 | if: github.event.repository.fork == false 10 | 11 | steps: 12 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2 13 | - run: | 14 | LIBRARIAN_RELEASE=true ./gradlew librarianPublishToMavenCentral 15 | env: 16 | LIBRARIAN_SONATYPE_PASSWORD: ${{ secrets.CENTRAL_PORTAL_PASSWORD }} 17 | LIBRARIAN_SONATYPE_USERNAME: ${{ secrets.CENTRAL_PORTAL_USERNAME }} 18 | LIBRARIAN_SIGNING_PRIVATE_KEY: ${{ secrets.GPG_KEY }} 19 | LIBRARIAN_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.GPG_KEY_PASSWORD }} 20 | -------------------------------------------------------------------------------- /tests/agp9-kmp/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.agp9.kmp) 3 | alias(libs.plugins.kgp.multiplatform) 4 | id("com.gradleup.tapmoc") 5 | id("check.publication") 6 | } 7 | 8 | val myJvmTarget = 11 9 | val myKotlinMetadataVersion = "2.0.0" 10 | 11 | tapmoc { 12 | java(myJvmTarget) 13 | kotlin(myKotlinMetadataVersion) 14 | } 15 | 16 | kotlin { 17 | jvm() 18 | android { 19 | namespace = "com.example" 20 | compileSdk = libs.versions.compile.sdk.get().toInt() 21 | } 22 | } 23 | 24 | checkPublication { 25 | jvmTarget.set(myJvmTarget) 26 | // 2.0.0 ends up as 1.9.9999, see https://github.com/Jetbrains/kotlin/blob/dbb50f240fc955d4207aec7f62000b77be289acd/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java#L140 27 | kotlinMetadataVersion.set("1.9.9999") 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /tests/agp8-java/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.android.build.gradle.internal.tasks.factory.dependsOn 2 | 3 | plugins { 4 | alias(libs.plugins.agp8) 5 | id("com.gradleup.tapmoc") 6 | id("check.publication") 7 | } 8 | 9 | val myJvmTarget = 11 10 | tapmoc { 11 | java(myJvmTarget) 12 | } 13 | 14 | android { 15 | defaultConfig { 16 | namespace = "com.example" 17 | minSdk = libs.versions.compile.sdk.get().toInt() 18 | compileSdk = libs.versions.compile.sdk.get().toInt() 19 | } 20 | 21 | 22 | publishing { 23 | singleVariant("release") { 24 | withSourcesJar() 25 | } 26 | } 27 | } 28 | 29 | checkPublication { 30 | jvmTarget.set(myJvmTarget) 31 | } 32 | 33 | java.sourceSets.create("foo") 34 | 35 | // Not sure why this is not automatically setup 36 | tasks.named("build").dependsOn("compileFooJava") 37 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/check-dependencies/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import tapmoc.Severity 2 | 3 | buildscript { 4 | dependencies { 5 | classpath("com.gradleup.tapmoc:tapmoc-gradle-plugin:PLACEHOLDER") 6 | } 7 | } 8 | 9 | plugins { 10 | alias(libs.plugins.kgp.jvm) 11 | } 12 | 13 | pluginManager.apply("com.gradleup.tapmoc") 14 | extensions.getByType(tapmoc.TapmocExtension::class.java).apply { 15 | java(11) 16 | kotlin("1.9.0") 17 | checkDependencies(Severity.WARNING) 18 | } 19 | 20 | dependencies { 21 | // makes `tapmocCheckKotlinMetadata` fail because incompatible metadata was exposed to consumers. 22 | api("org.jetbrains.kotlin:kotlin-stdlib:2.1.21") 23 | // makes `tapmocCheckKotlinStdlibVersions` fail because kotlin-stdlib was upgraded to a new version. 24 | implementation("com.squareup:kotlinpoet:2.2.0") 25 | api(libs.kotlin.metadata) 26 | } 27 | -------------------------------------------------------------------------------- /tests/build-logic/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.kgp.jvm) 3 | alias(libs.plugins.ksp) 4 | alias(libs.plugins.gratatouille) 5 | // No need to specify the version because we are always included 6 | // alongside the main tapmoc build and dependency substitution will kick in. 7 | id("com.gradleup.tapmoc") 8 | } 9 | 10 | group = "build-logic" 11 | 12 | dependencies { 13 | implementation(libs.kotlinx.json) 14 | implementation(libs.jsonpathkt) 15 | implementation(libs.cast) 16 | implementation(libs.kotlin.metadata) 17 | implementation(libs.asm) 18 | implementation(libs.gratatouille.wiring.runtime) 19 | implementation(libs.gratatouille.tasks.runtime) 20 | implementation(gradleApi()) 21 | } 22 | 23 | gratatouille { 24 | codeGeneration { 25 | addDependencies.set(false) 26 | } 27 | pluginLocalPublication("check.publication") 28 | } 29 | 30 | tapmoc { 31 | java(11) 32 | kotlin(embeddedKotlinVersion) 33 | } 34 | -------------------------------------------------------------------------------- /tapmoc-tasks/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.gradleup.librarian.gradle.Librarian 2 | import tapmoc.configureKotlinCompatibility 3 | import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion 4 | 5 | plugins { 6 | id("org.jetbrains.kotlin.jvm") 7 | id("com.gradleup.gratatouille.tasks") 8 | id("com.google.devtools.ksp") 9 | } 10 | 11 | Librarian.module(project) 12 | 13 | dependencies { 14 | implementation(libs.kotlin.metadata) 15 | implementation(libs.asm) 16 | implementation(libs.gratatouille.tasks.runtime) 17 | } 18 | 19 | // Override the default from Librarian, we want to be able to use the latest Kotlin version here. 20 | configureKotlinCompatibility(getKotlinPluginVersion()) 21 | 22 | gratatouille { 23 | codeGeneration { 24 | classLoaderIsolation() 25 | addDependencies.set(false) 26 | } 27 | } 28 | 29 | extensions.getByType().repositories { 30 | maven { 31 | name = "local" 32 | url = rootDir.resolve("build/m2").toURI() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/agp8-kotlin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 2 | 3 | plugins { 4 | alias(libs.plugins.agp8) 5 | alias(libs.plugins.kgp.android) 6 | id("com.gradleup.tapmoc") 7 | id("check.publication") 8 | } 9 | 10 | val myJvmTarget = 11 11 | val myKotlinMetadataVersion = "2.0.0" 12 | 13 | tapmoc { 14 | java(myJvmTarget) 15 | kotlin(myKotlinMetadataVersion) 16 | } 17 | 18 | android { 19 | publishing { 20 | singleVariant("release") { 21 | withSourcesJar() 22 | } 23 | } 24 | } 25 | 26 | checkPublication { 27 | jvmTarget.set(myJvmTarget) 28 | // 2.0.0 ends up as 1.9.9999, see https://github.com/Jetbrains/kotlin/blob/dbb50f240fc955d4207aec7f62000b77be289acd/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java#L140 29 | kotlinMetadataVersion.set("1.9.9999") 30 | } 31 | 32 | android { 33 | defaultConfig { 34 | namespace = "com.example" 35 | compileSdk = libs.versions.compile.sdk.get().toInt() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | __COPYRIGHT_LINE__ 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tests/agp9-kotlin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 2 | 3 | plugins { 4 | alias(libs.plugins.agp9.library) 5 | id("com.gradleup.tapmoc") 6 | id("check.publication") 7 | } 8 | 9 | val myJvmTarget = 11 10 | val myKotlinMetadataVersion = "2.0.0" 11 | 12 | tapmoc { 13 | java(myJvmTarget) 14 | kotlin(myKotlinMetadataVersion) 15 | } 16 | android { 17 | publishing { 18 | singleVariant("release") { 19 | withSourcesJar() 20 | } 21 | } 22 | } 23 | 24 | checkPublication { 25 | jvmTarget.set(myJvmTarget) 26 | // 2.0.0 ends up as 1.9.9999, see https://github.com/Jetbrains/kotlin/blob/dbb50f240fc955d4207aec7f62000b77be289acd/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java#L140 27 | kotlinMetadataVersion.set("1.9.9999") 28 | } 29 | 30 | android { 31 | defaultConfig { 32 | namespace = "com.example" 33 | compileSdk = libs.versions.compile.sdk.get().toInt() 34 | } 35 | } 36 | 37 | afterEvaluate { 38 | tasks.named("compileReleaseKotlin").get().apply { 39 | this as KotlinCompile 40 | // println("languageVersion=${this.compilerOptions.languageVersion.get()}") 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/api/tapmoc-gradle-plugin.api: -------------------------------------------------------------------------------- 1 | public final class tapmoc/CompatibilityKt { 2 | public static final fun configureJavaCompatibility (Lorg/gradle/api/Project;I)V 3 | public static final fun configureKotlinCompatibility (Lorg/gradle/api/Project;Ljava/lang/String;)V 4 | } 5 | 6 | public final class tapmoc/Severity : java/lang/Enum { 7 | public static final field ERROR Ltapmoc/Severity; 8 | public static final field IGNORE Ltapmoc/Severity; 9 | public static final field WARNING Ltapmoc/Severity; 10 | public static fun getEntries ()Lkotlin/enums/EnumEntries; 11 | public static fun valueOf (Ljava/lang/String;)Ltapmoc/Severity; 12 | public static fun values ()[Ltapmoc/Severity; 13 | } 14 | 15 | public abstract interface class tapmoc/TapmocExtension { 16 | public abstract fun checkApiDependencies (Ltapmoc/Severity;)V 17 | public abstract fun checkDependencies ()V 18 | public abstract fun checkDependencies (Ltapmoc/Severity;)V 19 | public abstract fun checkRuntimeDependencies (Ltapmoc/Severity;)V 20 | public abstract fun java (I)V 21 | public abstract fun kotlin (Ljava/lang/String;)V 22 | } 23 | 24 | public abstract class tapmoc/TapmocPlugin : org/gradle/api/Plugin { 25 | public fun ()V 26 | public synthetic fun apply (Ljava/lang/Object;)V 27 | public fun apply (Lorg/gradle/api/Project;)V 28 | } 29 | 30 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/src/agp/kotlin/tapmoc/internal/AgpImpl.kt: -------------------------------------------------------------------------------- 1 | package tapmoc.internal 2 | 3 | import com.android.build.api.dsl.CommonExtension 4 | import org.gradle.api.Action 5 | import org.gradle.api.JavaVersion 6 | import org.gradle.api.Project 7 | import org.gradle.api.plugins.AppliedPlugin 8 | 9 | private class AgpImpl(private val project: Project): Agp { 10 | override fun javaCompatibility(javaVersion: JavaVersion) { 11 | val android = project.extensions.findByName("android") as CommonExtension<*,*,*,*,*>? 12 | if (android != null) { 13 | android.compileOptions.apply { 14 | sourceCompatibility = javaVersion 15 | targetCompatibility = javaVersion 16 | } 17 | } else { 18 | /** 19 | * There is androidComponents {} but not android {} => This is the `com.android.kotlin.multiplatform.library` plugin 20 | * do nothing here, there is no compileJava task 21 | */ 22 | } 23 | } 24 | } 25 | 26 | 27 | /** 28 | * calls [block] if AGP is applied 29 | */ 30 | internal fun Project.onAgp(block: (Agp) -> Unit) { 31 | var hasAgp = false 32 | val callback = Action { 33 | if(!hasAgp) { 34 | hasAgp = true 35 | block(AgpImpl(this@onAgp)) 36 | } 37 | } 38 | pluginManager.withPlugin("com.android.application", callback) 39 | pluginManager.withPlugin("com.android.library", callback) 40 | pluginManager.withPlugin("com.android.test", callback) 41 | pluginManager.withPlugin("com.android.dynamic-feature", callback) 42 | pluginManager.withPlugin("com.android.kotlin.multiplatform.library", callback) 43 | } 44 | -------------------------------------------------------------------------------- /tapmoc-tasks/api/tapmoc-tasks.api: -------------------------------------------------------------------------------- 1 | public final class tapmoc/task/TapmocCheckClassFileVersionsEntryPoint { 2 | public static final field Companion Ltapmoc/task/TapmocCheckClassFileVersionsEntryPoint$Companion; 3 | public fun ()V 4 | public static final fun run (Ljava/util/function/BiConsumer;ZLjava/util/List;Ljava/lang/Integer;Ljava/io/File;)V 5 | } 6 | 7 | public final class tapmoc/task/TapmocCheckClassFileVersionsEntryPoint$Companion { 8 | public final fun run (Ljava/util/function/BiConsumer;ZLjava/util/List;Ljava/lang/Integer;Ljava/io/File;)V 9 | } 10 | 11 | public final class tapmoc/task/TapmocCheckKotlinMetadataVersionsEntryPoint { 12 | public static final field Companion Ltapmoc/task/TapmocCheckKotlinMetadataVersionsEntryPoint$Companion; 13 | public fun ()V 14 | public static final fun run (Ljava/util/function/BiConsumer;ZLjava/lang/String;Ljava/util/List;Ljava/io/File;)V 15 | } 16 | 17 | public final class tapmoc/task/TapmocCheckKotlinMetadataVersionsEntryPoint$Companion { 18 | public final fun run (Ljava/util/function/BiConsumer;ZLjava/lang/String;Ljava/util/List;Ljava/io/File;)V 19 | } 20 | 21 | public final class tapmoc/task/TapmocCheckKotlinStdlibVersionsEntryPoint { 22 | public static final field Companion Ltapmoc/task/TapmocCheckKotlinStdlibVersionsEntryPoint$Companion; 23 | public fun ()V 24 | public static final fun run (Ljava/util/function/BiConsumer;ZLjava/lang/String;Ljava/util/Set;Ljava/io/File;)V 25 | } 26 | 27 | public final class tapmoc/task/TapmocCheckKotlinStdlibVersionsEntryPoint$Companion { 28 | public final fun run (Ljava/util/function/BiConsumer;ZLjava/lang/String;Ljava/util/Set;Ljava/io/File;)V 29 | } 30 | 31 | -------------------------------------------------------------------------------- /tapmoc-tasks/src/main/kotlin/tapmoc/task/checkKotlinStdlibVersions.kt: -------------------------------------------------------------------------------- 1 | package tapmoc.task 2 | 3 | import gratatouille.tasks.GLogger 4 | import gratatouille.tasks.GOutputFile 5 | import gratatouille.tasks.GTask 6 | 7 | @GTask 8 | internal fun tapmocCheckKotlinStdlibVersions( 9 | logger: GLogger, 10 | warningAsError: Boolean, 11 | kotlinVersion: String?, 12 | kotlinStdlibVersions: Set, 13 | output: GOutputFile 14 | ) { 15 | if (kotlinVersion == null) { 16 | output.writeText("Tapmoc: skip checking Kotlin stdlib versions as no target Kotlin version is defined") 17 | return 18 | } 19 | 20 | val supportedVersion = kotlinVersion.toMinorVersion() 21 | kotlinStdlibVersions.forEach { version -> 22 | if (version.toMinorVersion() > supportedVersion) { 23 | logger.logOrFail(warningAsError, "Found incompatible kotlin-stdlib: '$version'. Maximum supported is '$supportedVersion'. Use `./gradlew dependencies to investigate the dependency tree.") 24 | } 25 | } 26 | 27 | output.writeText("Nothing to see here, this file is just a marker that the task executed successfully.") 28 | } 29 | 30 | private class MinorVersion(val major: Int, val minor: Int): Comparable { 31 | override fun toString(): String { 32 | return "$major.$minor" 33 | } 34 | override fun compareTo(other: MinorVersion): Int { 35 | return compareValuesBy(this, other, { it.major }, { it.minor }) 36 | } 37 | } 38 | 39 | private fun String.toMinorVersion(): MinorVersion { 40 | val c = split(".") 41 | require(c.size >= 2) { 42 | "Cannot parse Kotlin version '$this'. Expected format is major.minor.{extra}" 43 | } 44 | val supportedMajor = c[0].toInt() 45 | val supportedMinor = c[1].toInt() 46 | 47 | return MinorVersion(supportedMajor, supportedMinor) 48 | } 49 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/src/main/kotlin/tapmoc/compatibility.kt: -------------------------------------------------------------------------------- 1 | package tapmoc 2 | 3 | import tapmoc.internal.onAgp 4 | import org.gradle.api.JavaVersion 5 | import org.gradle.api.Project 6 | import org.gradle.api.tasks.compile.JavaCompile 7 | import tapmoc.internal.onKgp 8 | 9 | fun Project.configureJavaCompatibility( 10 | javaVersion: Int, 11 | ) { 12 | /** 13 | * Set --release for all JavaCompile tasks except the ones owned by AGP (if any). 14 | */ 15 | tasks.withType(JavaCompile::class.java).configureEach { 16 | if (!isAndroidJavaCompileTask(it.name)) { 17 | it.options.release.set(javaVersion) 18 | } 19 | } 20 | 21 | /** 22 | * Set the source and target compatibility for AGP (if any). 23 | */ 24 | onAgp { 25 | it.javaCompatibility(javaVersion.toJavaVersion()) 26 | } 27 | 28 | onKgp { 29 | it.javaCompatibility(javaVersion) 30 | } 31 | } 32 | 33 | 34 | fun Project.configureKotlinCompatibility( 35 | version: String, 36 | ) { 37 | require(version.split(".").size == 3) { 38 | "Tapmoc: cannot parse Kotlin version '$version'. Expected format is X.Y.Z." 39 | } 40 | 41 | onKgp { 42 | val kgpVersion = it.version(this) 43 | // We're using lexicographic comparison here 44 | if (version > kgpVersion) { 45 | error("Tapmoc: cannot set compatibility version '$version' because it is higher than the Kotlin Gradle Plugin version '$kgpVersion'") 46 | } 47 | it.kotlinCompatibility(version) 48 | } 49 | } 50 | 51 | internal fun Int.toJavaVersion(): JavaVersion { 52 | return JavaVersion.forClassVersion(this + 44) 53 | } 54 | 55 | private fun isAndroidJavaCompileTask(name: String): Boolean { 56 | /** 57 | * TODO: this isn't the most typesafe but not sure how to do better 58 | * 59 | * See https://cs.android.com/android-studio/platform/tools/base/+/da94db5fa35cdf1d97a02e705bf99fa4bf4676d4:build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/JavaCompile.kt;l=67 60 | */ 61 | return Regex("compile.*JavaWithJavac").matches(name) 62 | } 63 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/testProjects/java/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import javax.tools.DiagnosticCollector 2 | import javax.tools.JavaFileObject 3 | import javax.tools.StandardLocation 4 | import javax.tools.ToolProvider 5 | import tapmoc.Severity 6 | 7 | buildscript { 8 | dependencies { 9 | classpath("com.gradleup.tapmoc:tapmoc-gradle-plugin:PLACEHOLDER") 10 | } 11 | } 12 | 13 | plugins { 14 | id("java") 15 | } 16 | 17 | pluginManager.apply("com.gradleup.tapmoc") 18 | extensions.getByType(tapmoc.TapmocExtension::class.java).apply { 19 | java(8) 20 | kotlin("2.0.0") // This should be a no-op 21 | checkDependencies(Severity.ERROR) 22 | } 23 | 24 | abstract class GenerateClasses: DefaultTask() { 25 | @get:OutputDirectory 26 | abstract val output: DirectoryProperty 27 | 28 | @get:InputFile 29 | abstract val source: RegularFileProperty 30 | 31 | @TaskAction 32 | fun taskAction() { 33 | val javac = ToolProvider.getSystemJavaCompiler() 34 | val diagnostics = DiagnosticCollector() 35 | javac.getStandardFileManager(diagnostics, null, null).use { fm -> 36 | fm.setLocation(StandardLocation.CLASS_OUTPUT, listOf(output.get().asFile)) 37 | 38 | val javaSourceFiles = listOf(source.asFile.get()) 39 | val fileObjects = fm.getJavaFileObjectsFromFiles(javaSourceFiles) 40 | 41 | val options = buildList { 42 | add("--release") 43 | add("11") // Compile using a higher version 44 | } 45 | 46 | val task = javac.getTask(null, fm, diagnostics, options, null, fileObjects) 47 | 48 | val success = task.call() 49 | if (!success) { 50 | error("Java compilation failed.") 51 | } 52 | } 53 | } 54 | } 55 | 56 | val generateClasses = tasks.register("javaClasses", GenerateClasses::class.java) { 57 | output.set(file("build/javaClasses")) 58 | source.set(file("Hello.java")) 59 | } 60 | 61 | val jar = tasks.register("javaJar", Jar::class.java) { 62 | from(generateClasses) 63 | archiveClassifier = "higher" 64 | } 65 | 66 | dependencies { 67 | implementation(files(jar)) 68 | } 69 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.gradleup.librarian.gradle.Librarian 2 | 3 | plugins { 4 | id("org.jetbrains.kotlin.jvm") 5 | id("com.google.devtools.ksp") 6 | id("com.gradleup.gratatouille.wiring") 7 | } 8 | 9 | Librarian.module(project) 10 | 11 | val optionalPlugins = mapOf( 12 | "agp" to libs.agp, 13 | "kgp" to libs.kgp.compile.only, 14 | ) 15 | 16 | val mainCompilation = kotlin.target.compilations.getByName("main") 17 | 18 | optionalPlugins.forEach { (name, dependencyProvider) -> 19 | val compilation = kotlin.target.compilations.create(name) 20 | dependencies { 21 | add(compilation.compileOnlyConfigurationName, dependencyProvider) 22 | add(compilation.compileOnlyConfigurationName, libs.gradle.api) 23 | } 24 | 25 | mainCompilation.associateWith(compilation) 26 | tasks.jar { 27 | from(compilation.output.classesDirs) 28 | } 29 | 30 | /** 31 | * associateWith() pulls the secondary compilations into the main dependencies, 32 | * which we don't want. 33 | * 34 | * An alternative would be to not use `associateWith()` but that fails in the IDE, 35 | * probably because there is no way to set `AbstractKotlinCompile.friendSourceSets` 36 | * from public API. 37 | */ 38 | val dep = dependencyProvider.get() 39 | configurations.compileOnly.configure { 40 | dependencies.removeIf { 41 | when { 42 | it is ExternalDependency && it.group == dep.group && it.name == dep.name -> true 43 | else -> false 44 | } 45 | } 46 | } 47 | } 48 | 49 | dependencies { 50 | compileOnly(libs.gradle.api) 51 | implementation(libs.gratatouille.wiring.runtime) 52 | gratatouille(project(":tapmoc-tasks")) 53 | 54 | testImplementation(gradleTestKit()) 55 | testImplementation(kotlin("test")) 56 | } 57 | 58 | gratatouille { 59 | codeGeneration { 60 | addDependencies.set(false) 61 | } 62 | pluginLocalPublication("com.gradleup.tapmoc") 63 | } 64 | 65 | tasks.withType().configureEach { 66 | dependsOn("publishAllPublicationsToLocalRepository") 67 | dependsOn(":tapmoc-tasks:publishAllPublicationsToLocalRepository") 68 | } 69 | 70 | extensions.getByType().repositories { 71 | maven { 72 | name = "local" 73 | url = rootDir.resolve("build/m2").toURI() 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/src/test/kotlin/Tests.kt: -------------------------------------------------------------------------------- 1 | import java.io.File 2 | import java.util.Properties 3 | import kotlin.test.Test 4 | import org.gradle.testkit.runner.GradleRunner 5 | import org.junit.Assert.assertTrue 6 | 7 | class Tests { 8 | private fun gradleRunner(dir: File, vararg args: String): GradleRunner { 9 | return GradleRunner.create() 10 | .withProjectDir(dir) 11 | .withDebug(false) 12 | .withArguments(*args) 13 | .forwardOutput() 14 | } 15 | 16 | @Test 17 | fun wrongJavaBytecodeIsDetected() { 18 | withTestProject("java") { 19 | gradleRunner(it, "build").buildAndFail().apply { 20 | assertTrue(output.contains("targets class file version 55.0 (Java 11) which is newer than supported <= 52 (Java 8).")) 21 | } 22 | } 23 | } 24 | 25 | @Test 26 | fun metaInfIsExcluded() { 27 | withTestProject("java-meta-inf") { 28 | gradleRunner(it, "build").build() 29 | } 30 | } 31 | 32 | @Test 33 | fun checkDepenenciesDisplaysWarnings() { 34 | withTestProject("check-dependencies") { 35 | gradleRunner(it, "build", "--continue").build().apply { 36 | assertTrue(output.contains("contains unsupported metadata")) 37 | assertTrue(output.contains("incompatible kotlin-stdlib")) 38 | } 39 | } 40 | } 41 | 42 | @Test 43 | fun kotlinHigherThanKGPFails() { 44 | withTestProject("kotlin-higher-version") { 45 | gradleRunner(it, "build").buildAndFail().apply { 46 | assertTrue(output.contains("Tapmoc: cannot set compatibility version '2.3.0' because it is higher than the Kotlin Gradle Plugin version '2.2.0'")) 47 | } 48 | } 49 | } 50 | } 51 | 52 | 53 | private fun withTestProject(name: String, block: (File) -> Unit) { 54 | val src = File("testProjects/$name") 55 | val dst = File("build/testProject") 56 | dst.deleteRecursively() 57 | 58 | src.copyRecursively(dst) 59 | 60 | dst.walk().onLeave { 61 | if (it.isDirectory && it.name == "build") { 62 | it.deleteRecursively() 63 | } 64 | }.count() // count is just used to collect the sequence 65 | 66 | val currentVersion = Properties().apply { 67 | File("../librarian.root.properties").reader().use { 68 | load(it) 69 | } 70 | } 71 | dst.resolve("build.gradle.kts").let { 72 | it.writeText(it.readText().replace("PLACEHOLDER", currentVersion.get("pom.version").toString())) 73 | } 74 | block(dst) 75 | } 76 | -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | gratatouille-runtime = "0.1.2" 3 | gratatouille-build-time = "0.1.3-SNAPSHOT-ece70695061b18da18165c5203a180d1382abcbe" 4 | # Version of KGP we are using to build tapmoc 5 | kgp-latest = "2.3.0" 6 | ksp = "2.3.3" 7 | # Version of KGP tapmoc is compatible with at runtime 8 | kgp-compile-only = "1.9.0" 9 | compile-sdk = "36" 10 | agp9 = "9.0.0-beta02" 11 | nmcp = "1.3.1-SNAPSHOT-bd3a2d8eeaa63dce9dfc2c9d8b63f4a2a98a50e7" 12 | 13 | [libraries] 14 | #noinspection AndroidGradlePluginVersion 15 | gradle-api = "dev.gradleplugins:gradle-api:8.0" 16 | #noinspection AndroidGradlePluginVersion 17 | agp = "com.android.tools.build:gradle:8.2.0" 18 | kgp-compile-only = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kgp-compile-only" } 19 | gratatouille-tasks-runtime = { module = "com.gradleup.gratatouille:gratatouille-tasks-runtime", version.ref = "gratatouille-runtime" } 20 | gratatouille-wiring-runtime = { module = "com.gradleup.gratatouille:gratatouille-wiring-runtime", version.ref = "gratatouille-runtime" } 21 | kotlin-metadata = { module = "org.jetbrains.kotlin:kotlin-metadata-jvm", version.ref = "kgp-latest" } 22 | cast = "net.mbonnin.cast:cast:0.0.1" 23 | jsonpathkt = "com.eygraber:jsonpathkt-kotlinx:3.0.2" 24 | kotlinx-json = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0" 25 | asm = "org.ow2.asm:asm:9.9.1" 26 | tapmoc = "com.gradleup.tapmoc:tapmoc-gradle-plugin:0.0.3" 27 | nmcp-tasks = { module = "com.gradleup.nmcp:nmcp-tasks", version.ref = "nmcp" } 28 | 29 | [plugins] 30 | kgp-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kgp-latest" } 31 | kgp-android = { id = "org.jetbrains.kotlin.android", version.ref = "kgp-latest" } 32 | kgp-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kgp-latest" } 33 | #noinspection SimilarGradleDependency 34 | agp8 = { id = "com.android.library", version = "8.13.0" } 35 | agp9-kmp = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp9" } 36 | #noinspection SimilarGradleDependency 37 | agp9-library = { id = "com.android.library", version.ref = "agp9" } 38 | ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } 39 | librarian = { id = "com.gradleup.librarian", version = "0.2.2-SNAPSHOT-a938d327d264e6ecf3880659ebc1401d09370897" } 40 | #noinspection NewerVersionAvailable 41 | nmcp = { id = "com.gradleup.nmcp", version.ref = "nmcp" } 42 | #noinspection NewerVersionAvailable 43 | tapmoc = { id = "com.gradleup.tapmoc", version = "0.2.1-SNAPSHOT-dda1362c1d0f8389f50b362a08967793e320cf29" } 44 | gratatouille = { id = "com.gradleup.gratatouille", version.ref = "gratatouille-build-time" } 45 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/src/main/kotlin/tapmoc/TapmocExtension.kt: -------------------------------------------------------------------------------- 1 | package tapmoc 2 | 3 | interface TapmocExtension { 4 | /** 5 | * Configures the version of Java to target. 6 | * This version is used as: 7 | * - targetCompatibility 8 | * - sourceCompatibility 9 | * - release (if not on android) 10 | * 11 | * @param version the version of Java to target. 12 | * Examples: 8, 11, 17, 21, 24, ... 13 | */ 14 | fun java(version: Int) 15 | 16 | /** 17 | * Configures the version of Kotlin to target. 18 | * This version is used as: 19 | * - languageVersion 20 | * - apiVersion 21 | * - coreLibrariesVersion 22 | * 23 | * 24 | * @param version the version of Kotlin to target. 25 | * This is a string in case you need a specific minor version in `coreLibrariesVersion` 26 | * 27 | * Examples: "1.9.0", "1.9.22", "2.0.21", "2.1.20", ... 28 | */ 29 | fun kotlin(version: String) 30 | 31 | @Deprecated("Use checkDependencies instead.", ReplaceWith("checkDependencies(severity)")) 32 | fun checkApiDependencies(severity: Severity) 33 | 34 | @Deprecated("Use checkDependencies instead.", ReplaceWith("checkDependencies(severity)")) 35 | fun checkRuntimeDependencies(severity: Severity) 36 | 37 | /** 38 | * Walks the consumable configurations exposing a `java-api` or `java-runtime` [usage attribute](https://docs.gradle.org/9.2.1/javadoc/org/gradle/api/attributes/Usage.html) 39 | * and checks that dependencies are compatible with the target [java] and [kotlin] values: 40 | * 41 | * - checks that `kotlin-stdlib` is always <= targetKotlinVersion (`java-runtime` only) 42 | * - checks that Kotlin metadata is always <= targetKotlinVersion + 1 (`java-api` only). 43 | * Note: it is `targetKotlinVersion + 1` because Kotlin has a [best effort n + 1 forward compatibility guarantee](https://kotlinlang.org/docs/kotlin-evolution-principles.html#evolving-the-binary-format). 44 | * - checks that the Java class files version is always <= targetJavaVersion 45 | */ 46 | fun checkDependencies(severity: Severity) 47 | 48 | /** 49 | * Walks the consumable configurations exposing a `java-api` or `java-runtime` [usage attribute](https://docs.gradle.org/9.2.1/javadoc/org/gradle/api/attributes/Usage.html) 50 | * and checks that dependencies are compatible with the target [java] and [kotlin] values: 51 | * 52 | * - checks that `kotlin-stdlib` is always <= targetKotlinVersion (`java-runtime` only) 53 | * - checks that Kotlin metadata is always <= targetKotlinVersion + 1 (`java-api` only). 54 | * Note: it is `targetKotlinVersion + 1` because Kotlin has a [best effort n + 1 forward compatibility guarantee](https://kotlinlang.org/docs/kotlin-evolution-principles.html#evolving-the-binary-format). 55 | * - checks that the Java class files version is always <= targetJavaVersion 56 | */ 57 | fun checkDependencies() 58 | } 59 | 60 | enum class Severity { 61 | IGNORE, 62 | WARNING, 63 | ERROR 64 | } 65 | -------------------------------------------------------------------------------- /tapmoc-tasks/src/main/kotlin/tapmoc/task/checkKotlinMetadataVersions.kt: -------------------------------------------------------------------------------- 1 | package tapmoc.task 2 | 3 | import gratatouille.tasks.GClasspath 4 | import gratatouille.tasks.GLogger 5 | import gratatouille.tasks.GOutputFile 6 | import gratatouille.tasks.GTask 7 | import java.io.File 8 | import java.util.zip.ZipInputStream 9 | import kotlin.metadata.jvm.JvmMetadataVersion 10 | import kotlin.metadata.jvm.KotlinModuleMetadata 11 | import kotlin.metadata.jvm.UnstableMetadataApi 12 | 13 | @OptIn(UnstableMetadataApi::class) 14 | @GTask 15 | internal fun tapmocCheckKotlinMetadataVersions( 16 | logger: GLogger, 17 | warningAsError: Boolean, 18 | kotlinVersion: String?, 19 | files: GClasspath, 20 | output: GOutputFile 21 | ) { 22 | if (kotlinVersion == null) { 23 | output.writeText("Tapmoc: skip checking Kotlin metadata versions as no target Kotlin version is defined") 24 | return 25 | } 26 | 27 | val c = kotlinVersion.split(".") 28 | require(c.size == 3) { 29 | "Cannot parse Kotlin version $kotlinVersion. Expected format is X.Y.Z." 30 | } 31 | var supportedMajor = c[0].toInt() 32 | var supportedMinor = c[1].toInt() 33 | 34 | if (supportedMajor == 1 && supportedMinor == 9) { 35 | // 1.9 can read 2.0 metadata 36 | supportedMajor = 2 37 | supportedMinor = 0 38 | } else { 39 | // n + 1 forward compatibility in the general case 40 | supportedMinor += 1 41 | } 42 | 43 | val supportedVersion = JvmMetadataVersion(supportedMajor, supportedMinor, 0) 44 | 45 | files.forEach { fileWithPath -> 46 | fileWithPath.file.forEachModuleInfoFile { name, bytes -> 47 | val metadata = KotlinModuleMetadata.read(bytes) 48 | if (metadata.version > supportedVersion) { 49 | val extra = if (fileWithPath.file.name.startsWith("gradle-api")) { 50 | "\nIf you are using the `java-gradle-plugin` plugin, see https://github.com/GradleUp/Tapmoc/issues/69 for more details and workarounds." 51 | } else { 52 | "" 53 | } 54 | 55 | logger.logOrFail(warningAsError, "${fileWithPath.file.path}:$name contains unsupported metadata ${metadata.version} (expected: $kotlinVersion).$extra\nUse `./gradlew dependencies to investigate the dependency tree.") 56 | } 57 | } 58 | } 59 | 60 | output.writeText("Nothing to see here, this file is just a marker that the task executed successfully.") 61 | } 62 | 63 | private fun File.forEachModuleInfoFile(block: (String, ByteArray) -> Unit) { 64 | ZipInputStream(inputStream()).use { zis -> 65 | var entry = zis.nextEntry 66 | while (entry != null) { 67 | if (entry.name.matches(Regex("META-INF/.*\\.kotlin_module"))) { 68 | block(entry.name, zis.readBytes()) 69 | } 70 | entry = zis.nextEntry 71 | } 72 | } 73 | } 74 | 75 | internal fun GLogger.logOrFail(warningAsError: Boolean, message: String) { 76 | if (warningAsError) { 77 | kotlin.error(message) 78 | } else { 79 | warn("w: $message") 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 1>&2 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 48 | echo. 1>&2 49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 50 | echo location of your Java installation. 1>&2 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 1>&2 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 62 | echo. 1>&2 63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 64 | echo location of your Java installation. 1>&2 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /tests/gradle-plugin/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH= 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /tapmoc-tasks/src/main/kotlin/tapmoc/task/checkClassFileVersions.kt: -------------------------------------------------------------------------------- 1 | package tapmoc.task 2 | 3 | import gratatouille.tasks.GInputFiles 4 | import gratatouille.tasks.GLogger 5 | import gratatouille.tasks.GOutputFile 6 | import gratatouille.tasks.GTask 7 | import org.objectweb.asm.ClassReader 8 | import org.objectweb.asm.ClassVisitor 9 | import org.objectweb.asm.Opcodes 10 | import java.util.zip.ZipInputStream 11 | 12 | @GTask 13 | internal fun tapmocCheckClassFileVersions( 14 | logger: GLogger, 15 | warningAsError: Boolean, 16 | jarFiles: GInputFiles, 17 | javaVersion: Int?, 18 | output: GOutputFile, 19 | ) { 20 | if (javaVersion == null) { 21 | output.writeText("Tapmoc: skip checking class file versions as no target Java version is defined") 22 | return 23 | } 24 | val maxAllowedClassFileVersion = 44 + javaVersion 25 | 26 | jarFiles.forEach { fileWithPath -> 27 | ZipInputStream(fileWithPath.file.inputStream()).use { zis -> 28 | var entry = zis.nextEntry 29 | while (entry != null) { 30 | if (!entry.isDirectory 31 | && entry.name.endsWith(".class", ignoreCase = true) 32 | && !entry.name.startsWith("META-INF/versions") 33 | && !entry.name.startsWith("org/gradle/internal/impldep/META-INF/versions/") // See https://github.com/gradle/gradle/issues/24515 34 | ) { 35 | val classBytes = zis.readBytes() 36 | val cr = ClassReader(classBytes) 37 | var classFileVersion = -1.0 38 | 39 | cr.accept( 40 | object : ClassVisitor(Opcodes.ASM9) { 41 | override fun visit( 42 | version: Int, 43 | access: Int, 44 | name: String?, 45 | signature: String?, 46 | superName: String?, 47 | interfaces: Array?, 48 | ) { 49 | val minor = version.shr(16) 50 | val major = version and 0xFFFF 51 | 52 | // See https://javaalmanac.io/bytecode/versions/ 53 | classFileVersion = "$major.$minor".toDouble() 54 | } 55 | }, 56 | ClassReader.SKIP_CODE or ClassReader.SKIP_DEBUG or ClassReader.SKIP_FRAMES, 57 | ) 58 | 59 | if (classFileVersion > maxAllowedClassFileVersion) { 60 | val foundJavaVersion = if (classFileVersion >= 49) { 61 | (classFileVersion - 44).toInt() 62 | } else { 63 | when (classFileVersion) { 64 | 45.0 -> "1.0" 65 | 45.3 -> "1.1" 66 | 46.0 -> "1.2" 67 | 47.0 -> "1.3" 68 | 48.0 -> "1.4" 69 | else -> error("Unknown class file version: $classFileVersion") 70 | } 71 | } 72 | val humanReadable = "class file version $classFileVersion (Java ${foundJavaVersion})" 73 | val expectedHuman = "<= $maxAllowedClassFileVersion (Java $javaVersion)" 74 | val extra = if (fileWithPath.file.name.startsWith("gradle-api")) { 75 | "\nIf you are using the `java-gradle-plugin` plugin, see https://github.com/GradleUp/Tapmoc/issues/69 for more details and workarounds." 76 | } else { 77 | "" 78 | } 79 | logger.logOrFail( 80 | warningAsError, 81 | "${fileWithPath.file.path}:${entry.name} targets $humanReadable which is newer than supported $expectedHuman.$extra", 82 | ) 83 | } 84 | } 85 | entry = zis.nextEntry 86 | } 87 | } 88 | } 89 | 90 | output.writeText("Nothing to see here, this file is just a marker that the task executed successfully.") 91 | } 92 | 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Maven Central](https://img.shields.io/maven-central/v/com.gradleup.tapmoc/tapmoc-gradle-plugin?style=flat-square)](https://central.sonatype.com/namespace/com.gradleup.tapmoc) 2 | [![OSS Snapshots](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fcentral.sonatype.com%2Frepository%2Fmaven-snapshots%2Fcom%2Fgradleup%2Ftapmoc%2Ftapmoc-gradle-plugin%2Fmaven-metadata.xml&label=snapshots 3 | )]([https://oss.sonatype.org/content/repositories/snapshots/com/gradleup/tapmoc/](https://central.sonatype.com/repository/maven-snapshots/com/gradleup/tapmoc/tapmoc-gradle-plugin/maven-metadata.xml)) 4 | 5 | 6 | # Tapmoc 7 | 8 | Tapmoc helps you configure your Java/Kotlin compatibility flags: 9 | 10 | ```kotlin 11 | tapmoc { 12 | java(17) // build for Java 17, including source, target and api compatibility 13 | kotlin("2.1.0") // build for kotlin 2.1.0, including language and api version 14 | } 15 | ``` 16 | 17 | ### Rationale 18 | 19 | Configuring Java/Kotlin compatibility flags is a mundane task that comes with surprising amounts of questions: 20 | 21 | * What is the difference between `sourceCompatibility` and `targetCompatibility`? 22 | * Should I use `release` instead? 23 | * What does `release` even mean on Android? 24 | * Why do I need to configure Java compatibility if I only do Kotlin? 25 | * How do I configure `release` with Kotlin? 26 | * Should I use `tasks.withType` or `compilerOptions {}` or something else? 27 | * Is it "1.8" or "8" or `JavaVersion.VERSION_1_8`? 28 | * Is it `org.jetbrains.kotlin.gradle.dsl.KotlinVersion` or `kotlin.KotlinVersion`? 29 | * Is this working with KMP? 30 | * And more... 31 | 32 | Tapmoc handles all of that with just two simple functions! 33 | 34 | > [!NOTE] 35 | > The KMP ecosystem is a lot less mature than the JVM ecosystem and [non-JVM targets do not support apiVersion/languageVersion](https://youtrack.jetbrains.com/issue/KT-66755/). Compatibility flags only work for JVM targets. 36 | 37 | ### Usage 38 | 39 | ```kotlin 40 | plugins { 41 | // Add your Java/Kotlin/Android plugins here 42 | id("java") 43 | // or 44 | id("org.jetbrains.kotlin.jvm") 45 | // or 46 | id("org.jetbrains.kotlin.multiplatform") 47 | // or 48 | id("com.android.library") 49 | // etc... 50 | // And add the Tapmoc plugin 51 | id("com.gradleup.tapmoc").version("0.3.2") 52 | } 53 | 54 | /* 55 | * Configure all your Java/Kotlin targets with a single code block. 56 | * This code block works regardless of if you're using Kotlin/Android/KMP/etc... 57 | * You can copy/paste it 58 | */ 59 | tapmoc { 60 | // Java takes an int for simplicity 61 | java(17) 62 | // Kotlin takes a string so you have more control of the patch release of the stdlib. 63 | // languageVersion/apiVersion are configured with the minor version only. 64 | kotlin("2.1.0") 65 | 66 | // Optional: fail the build if any api dependency exposes incompatible Kotlin metadata, Kotlin stdlib or Java bytecode version. 67 | checkDependencies() 68 | } 69 | ``` 70 | 71 | If you have convention plugins, you can also use Tapmoc without all the plugin ceremony: 72 | 73 | ```kotlin 74 | import tapmoc.configureJavaCompatibility 75 | import tapmoc.configureKotlinCompatibility 76 | 77 | class ConventionPlugin: Plugin { 78 | override fun apply(target: Project) { 79 | target.configureJavaCompatibility(17) 80 | target.configureKotlinCompatibility("2.1.0") 81 | } 82 | } 83 | ``` 84 | 85 | That's it, you can now keep on with your life. 86 | 87 | ### Checking transitive dependencies 88 | 89 | Enforcing compiler flags works for your own code but doesn't check your dependencies. They may use incompatible APIs that will crash at runtime and/or produce incompatible metadata that will crash at build time. 90 | 91 | You can have tapmoc fail in such cases with `checkDependencies`: 92 | 93 | ```kotlin 94 | tapmoc { 95 | // Fail the build if any api dependency exposes incompatible Kotlin metadata, Kotlin stdlib or Java bytecode version. 96 | checkDependencies() 97 | } 98 | ``` 99 | 100 | ### Requirements: 101 | 102 | * Gradle 8.3+ 103 | * For Kotlin: Kotlin Gradle Plugin 1.9.0+ 104 | * For Android: Android Gradle Plugin 8.2.0+ 105 | 106 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.3.2 2 | _2025-12-16_ 3 | 4 | * [NEW] Ignore class files in `org/gradle/internal/impldep/META-INF/versions/` (#68) 5 | * [FIX] Fix parsing the java version for Java < 5 (#68) 6 | * [FIX] Fix downgrading the JVM kotlin-stdlib for KMP projects (#67, #69) 7 | 8 | # 0.3.1 9 | _2025-12-09_ 10 | 11 | * [NEW] Add a specific error message to warn about `java-gradle-plugin` adding `gradleApi()` in the wrong configuration (#65) 12 | * [FIX] Support for `com.android.test` and `com.android.dynamic-feature` plugins (#62, #63) 13 | * [BREAKING] Remove `com.gradleup.compat.patrouille` legacy plugin. It was only provided as a helper for the rename (#64) 14 | 15 | Many thanks @simonlebras for catching the `com.android.test` regression 🙏 16 | 17 | # 0.3.0 18 | _2025-12-08_ 19 | 20 | * [NEW] Add a specific error message to warn about `java-gradle-plugin` adding `gradleApi()` in the wrong configuration (#65) 21 | * [FIX] Support for `com.android.test` and `com.android.dynamic-feature` plugins (#62, #63) 22 | * [BREAKING] Remove `com.gradleup.compat.patrouille` legacy plugin. It was only provided as a helper for the rename (#64) 23 | 24 | # 0.2.0 25 | _2025-11-27_ 26 | 27 | ## Project is renamed to `tapmoc` 28 | 29 | `tapmoc` is backwards `compat`! Many thanks @JakeWharton for the nice name 💙 30 | 31 | You'll need to update your plugin id and extension block: 32 | 33 | ```kotlin 34 | plugins { 35 | // Replace 36 | id("com.gradleup.compat.patrouille").version("0.1.0") 37 | // With 38 | id("com.gradleup.tapmoc").version("0.2.0") 39 | } 40 | 41 | // replace 42 | compatPatrouille { 43 | java(17) 44 | kotlin("2.0.0") 45 | } 46 | 47 | // with 48 | tapmoc { 49 | java(17) 50 | kotlin("2.0.0") 51 | } 52 | ``` 53 | 54 | ## Other changes 55 | 56 | * `TapmocExtension::kotlin()` may now be called even if KGP is not present in the build classpath (#42). This makes it easier to use tapmoc in a central convention plugin. It also allows checking runtime dependencies for incompatible usages of `kotlin-stdlib` for Java projects that may rely on Kotlin dependencies. 57 | * Use `implementation` instead of `api` for the `kotlin-stdlib` configuration of non-JVM tests, fixes a warning when using KGP 2.3.0. (#41) 58 | * Make the plugin uses lazier Gradle APIs (#33, #34), many thanks @simonlebras. 59 | 60 | # 0.1.0 61 | _2025-10-10_ 62 | Add support for `com.android.kotlin.multiplatform.library` in https://github.com/GradleUp/compat-patrouille/pull/31 63 | 64 | # 0.0.3 65 | _2025-10-06_ 66 | 67 | Do not configure `JavaCompile` tasks eagerly (https://github.com/GradleUp/compat-patrouille/issues/27) 68 | 69 | # 0.0.3 70 | _2025-10-06_ 71 | 72 | Do not configure `JavaCompile` tasks eagerly (https://github.com/GradleUp/compat-patrouille/issues/27) 73 | 74 | # 0.0.2 75 | _2025-08-20_ 76 | 77 | A few bugfixes, upgrades and ergonomics improvements. Many thanks @OliverO2 and @Mr3zee for their feedback in this release. 78 | 79 | * [NEW] Add compatPatrouilleCheckRuntimeDependencies as a lifecycle task https://github.com/GradleUp/compat-patrouille/pull/23 80 | * [NEW] For JS and Wasm, add the KGP kotlin-stdlib instead of relying on `coreLibrariesVersion` https://github.com/GradleUp/compat-patrouille/pull/24 81 | * [FIX] Make checkApiDependencies lazier https://github.com/GradleUp/compat-patrouille/pull/20 82 | * [FIX] Fix KMP with multiple targets https://github.com/GradleUp/compat-patrouille/pull/21 83 | * [UPGRADE] Use latest kotlin-metadata lib https://github.com/GradleUp/compat-patrouille/pull/22 84 | 85 | # 0.0.1 86 | _2025-08-11_ 87 | 88 | Version `0.0.1` adds two new tasks to check the API and Runtime dependencies and fixes declaring the Kotlin compatibility of common source sets. 89 | 90 | * [NEW] Introduce `checkApiDependencies()` by @martinbonnin in https://github.com/GradleUp/compat-patrouille/pull/2 91 | * [NEW] Introduce `checkRuntimeDependencies()` by @martinbonnin in https://github.com/GradleUp/compat-patrouille/pull/16 92 | * [FIX] Fix detecting apiVersion in `commonMain` and `commonTest` source sets by @martinbonnin in https://github.com/GradleUp/compat-patrouille/pull/7 93 | * [UPDATE] update KGP, simplify GitHub actions files by @martinbonnin in https://github.com/GradleUp/compat-patrouille/pull/9 94 | * [UPDATE] Bump gradle to 9 by @martinbonnin in https://github.com/GradleUp/compat-patrouille/pull/15 95 | * [MISC] Add more integration tests by @martinbonnin in https://github.com/GradleUp/compat-patrouille/pull/10 96 | 97 | # 0.0.0 98 | _2025-04-08_ 99 | 100 | Initial release 🎉 101 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/src/main/kotlin/tapmoc/internal/TapmocExtensionImpl.kt: -------------------------------------------------------------------------------- 1 | package tapmoc.internal 2 | 3 | import org.gradle.api.NamedDomainObjectProvider 4 | import org.gradle.api.Project 5 | import org.gradle.api.artifacts.Configuration 6 | import org.gradle.api.artifacts.component.ModuleComponentIdentifier 7 | import org.gradle.api.attributes.Usage 8 | import org.gradle.api.provider.Property 9 | import org.gradle.language.base.plugins.LifecycleBasePlugin 10 | import tapmoc.Severity 11 | import tapmoc.TapmocExtension 12 | import tapmoc.configureJavaCompatibility 13 | import tapmoc.configureKotlinCompatibility 14 | import tapmoc.task.registerTapmocCheckClassFileVersionsTask 15 | import tapmoc.task.registerTapmocCheckKotlinMetadataVersionsTask 16 | import tapmoc.task.registerTapmocCheckKotlinStdlibVersionsTask 17 | 18 | internal abstract class TapmocExtensionImpl(private val project: Project) : TapmocExtension { 19 | private var kotlinMetadataSeverity = Severity.ERROR 20 | private var kotlinStdlibSeverity = Severity.ERROR 21 | 22 | private val apiDependencies: NamedDomainObjectProvider 23 | private val runtimeDependencies: NamedDomainObjectProvider 24 | 25 | abstract val kotlinVersionProvider: Property 26 | abstract val javaVersionProvider: Property 27 | 28 | init { 29 | apiDependencies = project.configurations.register("tapmocApiDependencies") { 30 | it.isCanBeConsumed = false 31 | it.isCanBeResolved = true 32 | it.isVisible = false 33 | 34 | it.attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, Usage.JAVA_API)) 35 | } 36 | 37 | runtimeDependencies = project.configurations.register("tapmocRuntimeDependencies") { 38 | it.isCanBeConsumed = false 39 | it.isCanBeResolved = true 40 | it.isVisible = false 41 | 42 | it.attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, Usage.JAVA_RUNTIME)) 43 | } 44 | 45 | val checkKotlinMetadatas = project.registerTapmocCheckKotlinMetadataVersionsTask( 46 | warningAsError = project.provider { kotlinMetadataSeverity == Severity.ERROR }, 47 | kotlinVersion = kotlinVersionProvider, 48 | files = project.files(apiDependencies), 49 | ) 50 | 51 | val checkKotlinStdlibs = project.registerTapmocCheckKotlinStdlibVersionsTask( 52 | warningAsError = project.provider { kotlinStdlibSeverity == Severity.ERROR }, 53 | kotlinVersion = kotlinVersionProvider, 54 | kotlinStdlibVersions = runtimeDependencies.map { 55 | it.incoming.resolutionResult.allComponents 56 | .mapNotNull { (it.id as? ModuleComponentIdentifier) } 57 | .filter { 58 | it.group == "org.jetbrains.kotlin" && it.module == "kotlin-stdlib" 59 | }.map { 60 | it.version 61 | }.toSet() 62 | }, 63 | ) 64 | 65 | val checkJavaClassFiles = project.registerTapmocCheckClassFileVersionsTask( 66 | warningAsError = project.provider { kotlinStdlibSeverity == Severity.ERROR }, 67 | javaVersion = javaVersionProvider, 68 | jarFiles = project.files(apiDependencies, runtimeDependencies) 69 | ) 70 | 71 | project.plugins.withType(LifecycleBasePlugin::class.java) { 72 | project.tasks.named(LifecycleBasePlugin.CHECK_TASK_NAME).configure { 73 | it.dependsOn(checkKotlinStdlibs) 74 | it.dependsOn(checkKotlinMetadatas) 75 | it.dependsOn(checkJavaClassFiles) 76 | } 77 | } 78 | } 79 | 80 | override fun java(version: Int) { 81 | javaVersionProvider.set(version) 82 | project.configureJavaCompatibility(version) 83 | } 84 | 85 | override fun kotlin(version: String) { 86 | kotlinVersionProvider.set(version) 87 | project.configureKotlinCompatibility(version) 88 | } 89 | 90 | override fun checkDependencies() { 91 | checkDependencies(Severity.ERROR) 92 | } 93 | 94 | @Suppress("DEPRECATION") 95 | override fun checkDependencies(severity: Severity) { 96 | checkApiDependencies(severity) 97 | checkRuntimeDependencies(severity) 98 | } 99 | 100 | @Deprecated("Use checkDependencies instead.", replaceWith = ReplaceWith("checkDependencies(severity)")) 101 | override fun checkApiDependencies(severity: Severity) { 102 | if (severity == Severity.IGNORE) { 103 | return 104 | } 105 | kotlinMetadataSeverity = severity 106 | 107 | apiDependencies.configure { 108 | it.dependencies.add(project.dependencies.project(mapOf("path" to project.path))) 109 | } 110 | } 111 | 112 | @Deprecated("Use checkDependencies instead.", replaceWith = ReplaceWith("checkDependencies(severity)")) 113 | override fun checkRuntimeDependencies(severity: Severity) { 114 | if (severity == Severity.IGNORE) { 115 | return 116 | } 117 | kotlinStdlibSeverity = severity 118 | 119 | runtimeDependencies.configure { 120 | it.dependencies.add(project.dependencies.project(mapOf("path" to project.path))) 121 | } 122 | } 123 | } 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /tests/build-logic/src/main/kotlin/check-publication.kt: -------------------------------------------------------------------------------- 1 | import cast.cast 2 | import com.nfeld.jsonpathkt.kotlinx.resolvePathOrNull 3 | import gratatouille.tasks.GInputFiles 4 | import gratatouille.tasks.GTask 5 | import gratatouille.wiring.GExtension 6 | import java.io.File 7 | import java.io.InputStream 8 | import java.util.zip.ZipInputStream 9 | import kotlin.metadata.jvm.KotlinModuleMetadata 10 | import kotlin.metadata.jvm.UnstableMetadataApi 11 | import kotlinx.serialization.json.Json 12 | import kotlinx.serialization.json.JsonArray 13 | import kotlinx.serialization.json.jsonPrimitive 14 | import org.gradle.api.Project 15 | import org.gradle.api.component.Component 16 | import org.gradle.api.component.SoftwareComponent 17 | import org.gradle.api.provider.Property 18 | import org.gradle.api.publish.PublishingExtension 19 | import org.gradle.api.publish.maven.MavenPublication 20 | import org.gradle.api.tasks.Delete 21 | import org.gradle.language.base.plugins.LifecycleBasePlugin 22 | import org.objectweb.asm.ClassReader 23 | import org.objectweb.asm.ClassVisitor 24 | import org.objectweb.asm.Opcodes 25 | 26 | @GExtension(pluginId = "check.publication", extensionName = "checkPublication") 27 | abstract class CheckPublicationExtension(project: Project) { 28 | abstract val jvmTarget: Property 29 | abstract val kotlinMetadataVersion: Property 30 | 31 | init { 32 | project.pluginManager.withPlugin("com.gradleup.tapmoc") { 33 | project.pluginManager.apply("maven-publish") 34 | 35 | with(project) { 36 | group = "com.example" 37 | extensions.getByType(PublishingExtension::class.java).apply { 38 | repositories { 39 | it.maven { 40 | it.name = "test" 41 | it.url = uri(file("build/m2")) 42 | } 43 | } 44 | publications { publications -> 45 | pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { 46 | publications.create("maven", MavenPublication::class.java) { publication -> 47 | publication.from(components.getByName("java")) 48 | } 49 | } 50 | pluginManager.withPlugin("com.android.library") { 51 | /** 52 | * Doc says to use afterEvaluate 🤷‍♂️ 53 | * https://developer.android.com/build/publish-library/upload-library 54 | */ 55 | afterEvaluate { 56 | publications.create("maven", MavenPublication::class.java) { publication -> 57 | publication.from(components.findByName("release")) 58 | } 59 | } 60 | } 61 | } 62 | } 63 | 64 | tasks.register("cleanM2", Delete::class.java) { 65 | delete(file("build/m2")) 66 | } 67 | tasks.named("publishAllPublicationsToTestRepository") { 68 | it.dependsOn("cleanM2") 69 | } 70 | 71 | val checkPublication = project.registerCheckPublicationTask( 72 | "checkPublication", 73 | m2Files = project.files(layout.buildDirectory.dir("m2")).asFileTree, 74 | jvmTarget = jvmTarget, 75 | kotlinMetadataVersion = kotlinMetadataVersion, 76 | ) 77 | checkPublication.configure { 78 | it.dependsOn("publishAllPublicationsToTestRepository") 79 | } 80 | 81 | project.plugins.withType(LifecycleBasePlugin::class.java) { 82 | project.tasks.named(LifecycleBasePlugin.CHECK_TASK_NAME).configure { 83 | it.dependsOn(checkPublication) 84 | } 85 | } 86 | } 87 | } 88 | } 89 | } 90 | 91 | 92 | @OptIn(UnstableMetadataApi::class) 93 | @GTask 94 | fun checkPublication(m2Files: GInputFiles, jvmTarget: Int, kotlinMetadataVersion: String?) { 95 | m2Files.groupBy { 96 | /** 97 | * com/example/agp9-kmp 98 | */ 99 | it.normalizedPath.split("/").take(3) 100 | }.values.forEach { 101 | checkPublicationInternal( 102 | publicationFiles = it.map { it.file }, 103 | jvmTarget = jvmTarget, 104 | kotlinMetadataVersion = kotlinMetadataVersion, 105 | ) 106 | } 107 | } 108 | 109 | @OptIn(UnstableMetadataApi::class) 110 | private fun checkJarFile(name: String, inputStream: InputStream, jvmTarget: Int, kotlinMetadataVersion: String?) { 111 | //println("checkJarFile '$name'") 112 | ZipInputStream(inputStream).let { zis -> 113 | var entry = zis.nextEntry 114 | while (entry != null) { 115 | if (entry.name.endsWith(".class")) { 116 | 117 | ClassReader(zis).accept( 118 | object : ClassVisitor(Opcodes.ASM9) { 119 | override fun visit( 120 | version: Int, 121 | access: Int, 122 | name: String?, 123 | signature: String?, 124 | superName: String?, 125 | interfaces: Array?, 126 | ) { 127 | check(version == jvmTarget + 44) { 128 | "${entry!!.name}: expected class files be of version '${jvmTarget + 44}', got '$version'" 129 | } 130 | } 131 | }, 132 | 0, 133 | ) 134 | } else if (kotlinMetadataVersion != null && entry.name.endsWith(".kotlin_module")) { 135 | val metadata = KotlinModuleMetadata.read(zis.readAllBytes()) 136 | metadata.version.apply { 137 | check( 138 | "$major.$minor.$patch" == kotlinMetadataVersion 139 | || kotlinMetadataVersion == "2.0.0" && "$major.$minor.$patch" == "1.9.9999", // kotlinc uses 1.9.9999 for 2.0.0. There is a good reason which I cannot remember today. 140 | ) { 141 | "${entry.name}: expected Kotlin metadata version '$kotlinMetadataVersion', got '$major.$minor.$patch'." 142 | } 143 | } 144 | } 145 | entry = zis.nextEntry 146 | } 147 | } 148 | } 149 | 150 | 151 | private fun checkPublicationInternal(publicationFiles: List, jvmTarget: Int, kotlinMetadataVersion: String?) { 152 | val moduleFiles = publicationFiles.filter { it.extension == "module" }.toList() 153 | 154 | check(moduleFiles.size == 1) { 155 | "Expected exactly one module file, got ${moduleFiles.size}: $moduleFiles" 156 | } 157 | 158 | moduleFiles.single().readText().let { 159 | Json.parseToJsonElement(it) 160 | }.resolvePathOrNull("$.variants.*.attributes[\"org.gradle.jvm.version\"]")!! 161 | .cast() 162 | .map { 163 | it.jsonPrimitive.content 164 | } 165 | .forEach { 166 | check(it == jvmTarget.toString()) { 167 | "Expected all modules to be built with Java '$jvmTarget', got $it" 168 | } 169 | } 170 | 171 | var found = false 172 | var jarFiles = 173 | publicationFiles.filter { (it.extension == "jar" && !it.name.endsWith("-sources.jar")) } 174 | .toList() 175 | if (jarFiles.size > 1) { 176 | "Too many jar files found, expected one, got ${jarFiles.size}: $jarFiles" 177 | } else if (jarFiles.size == 1) { 178 | found = true 179 | jarFiles.single().inputStream().use { 180 | checkJarFile(jarFiles.single().path, it, jvmTarget, kotlinMetadataVersion) 181 | } 182 | } 183 | 184 | if (found) { 185 | return 186 | } 187 | 188 | jarFiles = publicationFiles.filter { it.extension == "aar" }.toList() 189 | if (jarFiles.size > 1) { 190 | "Too many aar files found, expected one, got ${jarFiles.size}: $jarFiles" 191 | } else if (jarFiles.size == 1) { 192 | ZipInputStream(jarFiles.single().inputStream()).use { zis -> 193 | var entry = zis.nextEntry 194 | while (entry != null) { 195 | if (entry.name == "classes.jar") { 196 | if (found) { 197 | error("multiple classes.jar found in ${jarFiles.single()}") 198 | } 199 | found = true 200 | checkJarFile("${jarFiles.single().path}:${entry.name}", zis, jvmTarget, kotlinMetadataVersion) 201 | } 202 | entry = zis.nextEntry 203 | } 204 | } 205 | } 206 | 207 | if (found) { 208 | return 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /tapmoc-gradle-plugin/src/kgp/kotlin/tapmoc/internal/KgpImpl.kt: -------------------------------------------------------------------------------- 1 | package tapmoc.internal 2 | 3 | import java.lang.reflect.Method 4 | import org.gradle.api.Project 5 | import org.gradle.api.provider.ProviderFactory 6 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget 7 | import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension 8 | import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions 9 | import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions 10 | import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension 11 | import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension 12 | import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension 13 | import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension 14 | import org.jetbrains.kotlin.gradle.dsl.KotlinVersion 15 | import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin 16 | import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType 17 | import org.jetbrains.kotlin.gradle.plugin.KotlinTarget 18 | import org.jetbrains.kotlin.gradle.plugin.KotlinTargetsContainer 19 | import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion 20 | 21 | private var method: Method? = null 22 | private var firstTime = true 23 | 24 | @Synchronized 25 | private fun compilerOptionsMethod(): Method? { 26 | if (firstTime) { 27 | firstTime = false 28 | 29 | method = try { 30 | KotlinMultiplatformExtension::class.java.getMethod("getCompilerOptions") 31 | } catch (_: NoSuchMethodException) { 32 | null 33 | } 34 | } 35 | 36 | return method 37 | } 38 | 39 | private class KgpImpl(extension: Any, private val providers: ProviderFactory, private val kgpVersion: String) : Kgp { 40 | private val kotlinProjectExtension: KotlinProjectExtension = extension as KotlinProjectExtension 41 | 42 | override fun javaCompatibility(version: Int) { 43 | kotlinProjectExtension.forEachCompilerOptions { platformType -> 44 | when (this) { 45 | is KotlinJvmCompilerOptions -> { 46 | if (platformType != KotlinPlatformType.androidJvm) { 47 | /** 48 | * See https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/JavaCompileUtils.kt;l=410?q=Using%20%27--release%27%20option%20for%20JavaCompile%20is%20not%20supported%20because%20it%20prevents%20the%20Android%20Gradle%20plugin 49 | * 50 | * Note that when using 'org.jetbrains.kotlin.multiplatform', we still enter this branch but it looks like `-Xjdk-release` is ignored in that case. 51 | * See https://youtrack.jetbrains.com/issue/KT-81606/com.android.kotlin.multiplatform.library-doesnt-error-on-Xjdk-release-usage. 52 | */ 53 | freeCompilerArgs.add("-Xjdk-release=${version}") 54 | } 55 | /** 56 | * jvmTarget needs to be set as well, or we get an error such as 57 | * e: '-Xjdk-release=11' option conflicts with '-jvm-target 17'. Please remove the '-jvm-target' option 58 | */ 59 | this.jvmTarget.set(version.toJvmTarget()) 60 | } 61 | } 62 | } 63 | } 64 | 65 | override fun kotlinCompatibility(version: String) { 66 | val kotlinVersion = KotlinVersion.fromVersion(version.substringBeforeLast(".")) 67 | when (kotlinProjectExtension) { 68 | is KotlinAndroidProjectExtension -> { 69 | kotlinProjectExtension.compilerOptions { 70 | apiVersion.set(kotlinVersion) 71 | languageVersion.set(kotlinVersion) 72 | } 73 | } 74 | is KotlinJvmProjectExtension -> { 75 | kotlinProjectExtension.compilerOptions { 76 | apiVersion.set(kotlinVersion) 77 | languageVersion.set(kotlinVersion) 78 | } 79 | } 80 | is KotlinMultiplatformExtension -> { 81 | val compilerOptions = compilerOptionsMethod() 82 | if (compilerOptions != null) { 83 | (compilerOptions.invoke(kotlinProjectExtension) as KotlinCommonCompilerOptions).apply { 84 | /** 85 | * Kotlin 2.0+: it's important to set the version at the extension level for the shared source sets 86 | * like `commonMain` and `commonTest`. 87 | * 88 | * See https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-dsl-reference.html#compiler-options 89 | */ 90 | apiVersion.set(kotlinVersion) 91 | languageVersion.set(kotlinVersion) 92 | } 93 | } else { 94 | /** 95 | * Kotlin <2.0: not sure how we do the same thing. The IDE won't be able to get the proper information in 96 | * common source sets, but the final binaries should still target the correct version. 97 | */ 98 | kotlinProjectExtension.forEachCompilerOptions { 99 | apiVersion.set(kotlinVersion) 100 | languageVersion.set(kotlinVersion) 101 | } 102 | } 103 | } 104 | } 105 | 106 | /** 107 | * Wasm and JS require the latest kotlin stdlib 108 | * 109 | * See https://youtrack.jetbrains.com/issue/KT-66755/ 110 | */ 111 | val isStdlibDefaultDependencyEnabled = 112 | providers.gradleProperty("kotlin.stdlib.default.dependency") 113 | .map { it.toBooleanStrictOrNull() != false } 114 | .getOrElse(true) 115 | 116 | if (isStdlibDefaultDependencyEnabled) { 117 | /** 118 | * Downgrade the JVM stdlib version to avoid leaking incompatible metadata 119 | * 120 | * See https://github.com/Jetbrains/kotlin/blob/7fa1c5fdc7077e52d29505c6fa10a82a43665d7c/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/stdlibDependencyManagement.kt#L97 121 | */ 122 | kotlinProjectExtension.forEachTarget { target -> 123 | target.compilations.filter { it.name != "test" }.forEach { compilation -> 124 | compilation.defaultSourceSet.dependencies { 125 | if (target.platformType in setOf(KotlinPlatformType.jvm, KotlinPlatformType.androidJvm, KotlinPlatformType.common)) { 126 | api("org.jetbrains.kotlin:kotlin-stdlib:${version}") 127 | } else { 128 | // Non-JVM targets do not support compatibility flags and require the latest version of kotlin-stdlib 129 | api("org.jetbrains.kotlin:kotlin-stdlib:${kgpVersion}") 130 | } 131 | } 132 | } 133 | } 134 | } 135 | } 136 | 137 | override fun version(project: Project): String { 138 | return project.getKotlinPluginVersion() 139 | } 140 | } 141 | 142 | /** 143 | * See https://github.com/JetBrains/kotlin/blob/32a701d1ee0ffc79eb189b911acc5df4008e9ed4/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/utils/kotlinExtensionUtils.kt#L23 144 | */ 145 | private fun KotlinProjectExtension.forEachTarget(block: (KotlinTarget) -> Unit) { 146 | when (this) { 147 | is KotlinTargetsContainer -> targets.configureEach(block) 148 | is KotlinSingleTargetExtension<*> -> block(target) 149 | else -> error("Unsupported Kotlin project extension type: ${this::class.simpleName}") 150 | } 151 | } 152 | 153 | private fun Int.toJvmTarget(): JvmTarget { 154 | return when (this) { 155 | 8 -> JvmTarget.JVM_1_8 156 | else -> JvmTarget.fromTarget(this.toString()) 157 | } 158 | } 159 | 160 | internal fun KotlinProjectExtension.forEachCompilerOptions(block: KotlinCommonCompilerOptions.(platformType: KotlinPlatformType) -> Unit) { 161 | when (this) { 162 | is KotlinJvmProjectExtension -> compilerOptions.block(KotlinPlatformType.jvm) 163 | is KotlinAndroidProjectExtension -> compilerOptions.block(KotlinPlatformType.androidJvm) 164 | is KotlinMultiplatformExtension -> { 165 | targets.configureEach { target -> 166 | target.compilations.configureEach { 167 | it.compileTaskProvider.configure { 168 | it.compilerOptions.block(target.platformType) 169 | } 170 | } 171 | } 172 | } 173 | else -> error("Unknown kotlin extension $this") 174 | } 175 | } 176 | 177 | /** 178 | * calls [block] if KGP is applied 179 | */ 180 | internal fun Project.onKgp(block: (Kgp) -> Unit) { 181 | // Guard against Java-only projects 182 | try { 183 | Class.forName("org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin") 184 | } catch (_: ClassNotFoundException) { 185 | return 186 | } 187 | 188 | var hasKgp = false 189 | /** 190 | * See https://github.com/gradle/gradle/issues/34995 191 | */ 192 | plugins.withType(KotlinBasePlugin::class.java).configureEach { 193 | if(!hasKgp) { 194 | hasKgp = true 195 | block(KgpImpl(extensions.getByName("kotlin"), providers, getKotlinPluginVersion())) 196 | } 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /tests/gradle-plugin/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH="\\\"\\\"" 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | if ! command -v java >/dev/null 2>&1 137 | then 138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 139 | 140 | Please set the JAVA_HOME variable in your environment to match the 141 | location of your Java installation." 142 | fi 143 | fi 144 | 145 | # Increase the maximum file descriptors if we can. 146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 147 | case $MAX_FD in #( 148 | max*) 149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 150 | # shellcheck disable=SC2039,SC3045 151 | MAX_FD=$( ulimit -H -n ) || 152 | warn "Could not query maximum file descriptor limit" 153 | esac 154 | case $MAX_FD in #( 155 | '' | soft) :;; #( 156 | *) 157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 158 | # shellcheck disable=SC2039,SC3045 159 | ulimit -n "$MAX_FD" || 160 | warn "Could not set maximum file descriptor limit to $MAX_FD" 161 | esac 162 | fi 163 | 164 | # Collect all arguments for the java command, stacking in reverse order: 165 | # * args from the command line 166 | # * the main class name 167 | # * -classpath 168 | # * -D...appname settings 169 | # * --module-path (only if needed) 170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 171 | 172 | # For Cygwin or MSYS, switch paths to Windows format before running java 173 | if "$cygwin" || "$msys" ; then 174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 176 | 177 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 178 | 179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 180 | for arg do 181 | if 182 | case $arg in #( 183 | -*) false ;; # don't mess with options #( 184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 185 | [ -e "$t" ] ;; #( 186 | *) false ;; 187 | esac 188 | then 189 | arg=$( cygpath --path --ignore --mixed "$arg" ) 190 | fi 191 | # Roll the args list around exactly as many times as the number of 192 | # args, so each arg winds up back in the position where it started, but 193 | # possibly modified. 194 | # 195 | # NB: a `for` loop captures its iteration list before it begins, so 196 | # changing the positional parameters here affects neither the number of 197 | # iterations, nor the values presented in `arg`. 198 | shift # remove old arg 199 | set -- "$@" "$arg" # push replacement arg 200 | done 201 | fi 202 | 203 | 204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 206 | 207 | # Collect all arguments for the java command: 208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 209 | # and any embedded shellness will be escaped. 210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 211 | # treated as '${Hostname}' itself on the command line. 212 | 213 | set -- \ 214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 215 | -classpath "$CLASSPATH" \ 216 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ 217 | "$@" 218 | 219 | # Stop when "xargs" is not available. 220 | if ! command -v xargs >/dev/null 2>&1 221 | then 222 | die "xargs is not available" 223 | fi 224 | 225 | # Use "xargs" to parse quoted args. 226 | # 227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 228 | # 229 | # In Bash we could simply go: 230 | # 231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 232 | # set -- "${ARGS[@]}" "$@" 233 | # 234 | # but POSIX shell has neither arrays nor command substitution, so instead we 235 | # post-process each arg (as a line of input to sed) to backslash-escape any 236 | # character that might be a shell metacharacter, then use eval to reverse 237 | # that process (while maintaining the separation between arguments), and wrap 238 | # the whole thing up as a single "set" statement. 239 | # 240 | # This will of course break if any of these variables contains a newline or 241 | # an unmatched quote. 242 | # 243 | 244 | eval "set -- $( 245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 246 | xargs -n1 | 247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 248 | tr '\n' ' ' 249 | )" '"$@"' 250 | 251 | exec "$JAVACMD" "$@" 252 | --------------------------------------------------------------------------------