diff --git a/.github/workflows/build-pull-request.yaml b/.github/workflows/build-pull-request.yaml new file mode 100644 index 0000000..ed9936a --- /dev/null +++ b/.github/workflows/build-pull-request.yaml @@ -0,0 +1,13 @@ +name: Build pull request + +on: pull_request + +jobs: + build-pull-request: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7 + - uses: gradle/actions/setup-gradle@dbbdc275be76ac10734476cc723d82dfe7ec6eda #v3.4.2 + - run: | + ./gradlew build diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index 438d25d..0000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,29 +0,0 @@ -name: CI - -on: - push: - branches: [ main ] - tags: - - '*' - pull_request: - paths-ignore: - - 'docs/**' - - '*.md' - -jobs: - ci: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - uses: gradle/gradle-build-action@v2 - - name: Run the CI task - run: ./gradlew ci && ./gradlew -p test-plugin build - env: - GRADLE_KEY: ${{ secrets.GRADLE_KEY }} - GRADLE_SECRET: ${{ secrets.GRADLE_SECRET }} - OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} - OSSRH_USER: ${{ secrets.OSSRH_USER }} - GPG_KEY: ${{ secrets.GPG_KEY }} - GPG_KEY_PASSWORD: ${{ secrets.GPG_KEY_PASSWORD }} - COM_GRADLEUP_PROFILE_ID: ${{ secrets.COM_GRADLEUP_PROFILE_ID }} diff --git a/.github/workflows/publish-pages.yaml b/.github/workflows/publish-pages.yaml new file mode 100644 index 0000000..479fccc --- /dev/null +++ b/.github/workflows/publish-pages.yaml @@ -0,0 +1,26 @@ +name: Publish documentation + +on: + push: + branches: ["main"] + workflow_dispatch: + +jobs: + build-docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7 + with: + fetch-depth: 0 + + - uses: gradle/actions/setup-gradle@dbbdc275be76ac10734476cc723d82dfe7ec6eda #v3.4.2 + - run: | + export JAVA_HOME=$JAVA_HOME_21_X64 # Remove when ubuntu-latest updates to Java 21 + ./gradlew dokkatooGeneratePublicationHtml + mkdir -p build/static + cp -rf build/dokka/html build/static/kdoc + + - uses: JamesIves/github-pages-deploy-action@94f3c658273cf92fb48ef99e5fbc02bd2dc642b2 #v4.6.3 + with: + branch: gh-pages # The branch the action should deploy to. + folder: build/static # The folder the action should deploy. diff --git a/.github/workflows/publish-release.yaml b/.github/workflows/publish-release.yaml new file mode 100644 index 0000000..aef810b --- /dev/null +++ b/.github/workflows/publish-release.yaml @@ -0,0 +1,27 @@ +name: Publish release + +on: + workflow_dispatch: + push: + tags: + - '*' + +jobs: + publish-release: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7 + with: + # See https://github.com/cli/cli/issues/9558 + ref: ${{ github.ref }} + - uses: gradle/actions/setup-gradle@dbbdc275be76ac10734476cc723d82dfe7ec6eda #v3.4.2 + - run: | + ./gradlew librarianPublishToMavenCentral + gh release create $GITHUB_REF_NAME --title $GITHUB_REF_NAME --verify-tag --notes-from-tag + env: + LIBRARIAN_SONATYPE_USERNAME: ${{ secrets.OSSRH_USER }} + LIBRARIAN_SONATYPE_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + LIBRARIAN_SIGNING_PRIVATE_KEY: ${{ secrets.GPG_KEY }} + LIBRARIAN_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.GPG_KEY_PASSWORD }} + GH_TOKEN: ${{ github.token }} \ No newline at end of file diff --git a/.github/workflows/publish-snapshot.yaml b/.github/workflows/publish-snapshot.yaml new file mode 100644 index 0000000..9cc2a73 --- /dev/null +++ b/.github/workflows/publish-snapshot.yaml @@ -0,0 +1,19 @@ +name: Publish snapshot + +on: + push: + branches: [ main ] +jobs: + publish-snapshot: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7 + - uses: gradle/actions/setup-gradle@dbbdc275be76ac10734476cc723d82dfe7ec6eda #v3.4.2 + - run: | + ./gradlew librarianPublishToSnapshots + env: + LIBRARIAN_SONATYPE_USERNAME: ${{ secrets.OSSRH_USER }} + LIBRARIAN_SONATYPE_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + LIBRARIAN_SIGNING_PRIVATE_KEY: ${{ secrets.GPG_KEY }} + LIBRARIAN_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.GPG_KEY_PASSWORD }} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5576e79 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# Next version (unreleased) + +* Update R8 +* Modernize build diff --git a/README.md b/README.md index f0eabaf..121e83c 100644 --- a/README.md +++ b/README.md @@ -146,3 +146,6 @@ Yes, the [Gradle Worker API](https://docs.gradle.org/current/userguide/worker_ap Yes. Because every plugin now relocates its own version of `kotlin-stdlib`, `okio` and other dependendancies, it means more work for the Classloaders and more Metaspace being used. There's a risk that builds will use more memory although it hasn't been a big issue so far. +**What does this bring compared to using R8 directly in a `JavaExec` task?** + +Using R8 directly from a `JavaExec` works as well. GR8 adds a few extra things like the ability to filter out some files in the dependencies. This is useful for an example to remove the dependencies rules that are otherwise automatically imported by R8. \ No newline at end of file diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 8749522..365a438 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -1,37 +1,13 @@ plugins { - `embedded-kotlin` - id("java-gradle-plugin") + id("java") } -plugins.apply(org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverGradleSubplugin::class.java) -extensions.configure(org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverExtension::class.java) { - annotations(HasImplicitReceiver::class.qualifiedName!!) -} - -repositories { - mavenCentral() - gradlePluginPortal() -} +group = "build-logic" dependencies { - implementation("net.mbonnin.vespene:vespene-lib:0.5") - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21") - implementation("com.gradle.publish:plugin-publish-plugin:0.15.0") - implementation("com.gradleup:gr8-plugin:0.6") + implementation(libs.vespene) + implementation(libs.kgp) + implementation(libs.gradle.publish) + implementation(libs.gr8.published) + implementation(libs.librarian) } - -gradlePlugin { - plugins { - register("gr8.build.common") { - id = "gr8.build.common" - implementationClass = "gr8.CommonPlugin" - } - - register("gr8.build.publishing") { - id = "gr8.build.publishing" - implementationClass = "gr8.PublishingPlugin" - } - } -} - -java.toolchain.languageVersion.set(JavaLanguageVersion.of(8)) \ No newline at end of file diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts index e69de29..ca47cd7 100644 --- a/build-logic/settings.gradle.kts +++ b/build-logic/settings.gradle.kts @@ -0,0 +1,9 @@ +dependencyResolutionManagement { + this.versionCatalogs { + this.create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} + +apply(from = "../gradle/repositories.gradle.kts") diff --git a/build-logic/src/main/kotlin/gr8/CommonPlugin.kt b/build-logic/src/main/kotlin/gr8/CommonPlugin.kt deleted file mode 100644 index cf596cf..0000000 --- a/build-logic/src/main/kotlin/gr8/CommonPlugin.kt +++ /dev/null @@ -1,25 +0,0 @@ -package gr8 - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.jvm.toolchain.JavaLanguageVersion - -class CommonPlugin : Plugin { - override fun apply(target: Project) { - with(target) { - plugins.apply("org.jetbrains.kotlin.jvm") - - extensions.getByType(JavaPluginExtension::class.java).toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) - } - dependencies.apply { - add("compileOnly", "org.jetbrains.kotlin:kotlin-stdlib") // let the Gradle plugin decide the version - } - - rootProject.tasks.named("ci") { - dependsOn(tasks.named("build")) - } - } - } -} diff --git a/build-logic/src/main/kotlin/gr8/PublishingPlugin.kt b/build-logic/src/main/kotlin/gr8/PublishingPlugin.kt deleted file mode 100644 index f341ba7..0000000 --- a/build-logic/src/main/kotlin/gr8/PublishingPlugin.kt +++ /dev/null @@ -1,203 +0,0 @@ -package gr8 - -import com.gradle.publish.PluginBundleExtension -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.plugins.ExtraPropertiesExtension -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.api.tasks.TaskProvider -import org.gradle.jvm.tasks.Jar -import org.gradle.plugins.signing.Sign -import org.gradle.plugins.signing.SigningExtension -import java.util.* - -class PublishingPlugin : Plugin { - override fun apply(target: Project) { - with(target) { - plugins.apply("signing") - plugins.apply("maven-publish") - - - group = "com.gradleup" - version = "0.10" - - val projectVersion = version - - project.extensions.extraProperties.set("gradle.publish.key", System.getenv("GRADLE_KEY")) - project.extensions.extraProperties.set("gradle.publish.secret", System.getenv("GRADLE_SECRET")) - - extensions.create("gr8Publishing", PublishingOptions::class.java) - - fun Project.getOssStagingUrl(): String { - val url = try { - this.rootProject.extensions.extraProperties["ossStagingUrl"] as String? - } catch (e: ExtraPropertiesExtension.UnknownPropertyException) { - null - } - if (url != null) { - return url - } - val client = net.mbonnin.vespene.lib.NexusStagingClient( - username = System.getenv("OSSRH_USER"), - password = System.getenv("OSSRH_PASSWORD"), - ) - val repositoryId = kotlinx.coroutines.runBlocking { - client.createRepository( - profileId = System.getenv("COM_GRADLEUP_PROFILE_ID"), - description = "$group:$name $projectVersion" - ) - } - println("publishing to '$repositoryId") - return "https://oss.sonatype.org/service/local/staging/deployByRepositoryId/${repositoryId}/".also { - this.rootProject.extensions.extraProperties["ossStagingUrl"] = it - } - } - - val publishing = extensions.getByType(PublishingExtension::class.java) - publishing.apply { - repositories { - maven { - name = "ossSnapshots" - url = uri("https://oss.sonatype.org/content/repositories/snapshots/") - credentials { - username = System.getenv("OSSRH_USER") - password = System.getenv("OSSRH_PASSWORD") - } - } - - maven { - name = "ossStaging" - setUrl { - uri(rootProject.getOssStagingUrl()) - } - credentials { - username = System.getenv("OSSRH_USER") - password = System.getenv("OSSRH_PASSWORD") - } - } - } - } - - extensions.getByType(SigningExtension::class.java).apply { - // GPG_PRIVATE_KEY should contain the armoured private key that starts with -----BEGIN PGP PRIVATE KEY BLOCK----- - // It can be obtained with gpg --armour --export-secret-keys KEY_ID - useInMemoryPgpKeys(System.getenv("GPG_KEY"), System.getenv("GPG_KEY_PASSWORD")) - sign(publishing.publications) - } - - tasks.withType(Sign::class.java).configureEach { - isEnabled = !System.getenv("GPG_KEY").isNullOrBlank() - } - - plugins.withId("java-gradle-plugin") { - plugins.apply("com.gradle.plugin-publish") - extensions.findByType(PluginBundleExtension::class.java)?.apply { - website = "https://github.com/GradleUp/gr8" - vcsUrl = "https://github.com/GradleUp/gr8" - tags = listOf("gradle", "r8", "gr8") - } - } - - fun isTag(): Boolean { - val ref = System.getenv("GITHUB_REF") - - return ref?.startsWith("refs/tags/") == true - } - - if (isTag()) { - rootProject.tasks.named("ci") { - dependsOn(tasks.named("publishAllPublicationsToOssStagingRepository")) - plugins.withId("com.gradle.plugin-publish") { - dependsOn(tasks.named("publishPlugins")) - } - } - } - } - } - - - open class PublishingOptions { - open fun Project.configurePublications(pomName: String, pomDescription: String) { - val publishing = extensions.getByType(PublishingExtension::class.java) - publishing.apply { - publications.withType(MavenPublication::class.java) { - if (!this.name.lowercase(Locale.ROOT).contains("marker")) { - artifact(createJavaSourcesTask()) - artifact(emptyJavadocJarTaskProvider()) - } - setDefaultPomFields(this, pomName, pomDescription) - } - } - } - } - - companion object { - fun Project.setDefaultPomFields( - mavenPublication: MavenPublication, - pomName: String, - pomDescription: String - ) { - mavenPublication.groupId = group.toString() - mavenPublication.version = version.toString() - mavenPublication.artifactId = "gr8-$name" - - mavenPublication.pom { - name.set(pomName) - description.set(pomDescription) - - val githubUrl = "https://github.com/gradleup/gr8" - - url.set(githubUrl) - - scm { - url.set(githubUrl) - connection.set(githubUrl) - developerConnection.set(githubUrl) - } - - licenses { - license { - name.set("MIT License") - url.set("https://github.com/GradleUp/gr8/blob/main/LICENSE") - } - } - - developers { - developer { - id.set("GradleUp authors") - name.set("GradleUp authors") - } - } - } - } - - private fun Project.createJavaSourcesTask(): TaskProvider { - try { - @Suppress("UNCHECKED_CAST") - return tasks.named("javaSourcesJar") as TaskProvider - } catch (e: Throwable) { - // Ignored - } - return tasks.register("javaSourcesJar", Jar::class.java) { - /** - * Add a dependency on the compileKotlin task to make sure the generated sources like - * antlr or SQLDelight get included - * See also https://youtrack.jetbrains.com/issue/KT-47936 - */ - dependsOn("compileKotlin") - - archiveClassifier.set("sources") - val sourceSets = project.extensions.getByType(JavaPluginExtension::class.java).sourceSets - from(sourceSets.getByName("main").allSource) - } - } - - private fun Project.emptyJavadocJarTaskProvider(): TaskProvider { - return tasks.register("emptyJavadocJar", org.gradle.jvm.tasks.Jar::class.java) { - archiveClassifier.set("javadoc") - } - } - } -} diff --git a/build.gradle.kts b/build.gradle.kts index dbaf635..cfd25ec 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,15 @@ -plugins { - id("gr8.build.common").apply(false) +import com.gradleup.librarian.gradle.librarianRoot + +buildscript { + dependencies { + classpath("build-logic:build-logic") + } + + repositories { + mavenCentral() + gradlePluginPortal() + google() + } } -tasks.register("ci") \ No newline at end of file +librarianRoot() \ No newline at end of file diff --git a/gr8-plugin-common/api/gr8-plugin-common.api b/gr8-plugin-common/api/gr8-plugin-common.api new file mode 100644 index 0000000..53c5767 --- /dev/null +++ b/gr8-plugin-common/api/gr8-plugin-common.api @@ -0,0 +1,115 @@ +public final class com/gradleup/gr8/DetectDuplicatesKt { + public static final fun detectDuplicates (Lorg/gradle/api/file/FileCollection;Lkotlin/jvm/functions/Function1;)V + public static synthetic fun detectDuplicates$default (Lorg/gradle/api/file/FileCollection;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V +} + +public abstract interface class com/gradleup/gr8/EachEntryConfiguration { + public abstract fun changeContents (Ljava/io/InputStream;)V + public abstract fun getEntry ()Ljava/util/zip/ZipEntry; + public abstract fun inputStream ()Ljava/io/InputStream; + public abstract fun rename (Ljava/lang/String;)V + public abstract fun skip (Z)V +} + +public final class com/gradleup/gr8/EachEntryConfiguration$DefaultImpls { + public static synthetic fun skip$default (Lcom/gradleup/gr8/EachEntryConfiguration;ZILjava/lang/Object;)V +} + +public abstract interface class com/gradleup/gr8/EachFileConfiguration { + public abstract fun changeContents (Ljava/io/InputStream;)V + public abstract fun getFile ()Ljava/io/File; + public abstract fun rename (Ljava/lang/String;)V + public abstract fun skip (Z)V +} + +public abstract class com/gradleup/gr8/EmbeddedJarTask : org/gradle/api/DefaultTask { + public fun ()V + public final fun mainJar (Lorg/gradle/api/provider/Provider;)V + public final fun otherJars (Ljava/lang/Object;)V + public final fun outputJar ()Lorg/gradle/api/provider/Provider; + public final fun outputJar (Ljava/io/File;)V + public final fun taskAction ()V +} + +public class com/gradleup/gr8/Gr8Configurator { + public fun (Ljava/lang/String;Lorg/gradle/api/Project;Lorg/gradle/jvm/toolchain/JavaToolchainService;)V + public final fun archiveName (Ljava/lang/String;)V + public final fun classPathConfiguration (Ljava/lang/String;)V + public final fun configuration (Ljava/lang/String;)V + public final fun exclude (Ljava/lang/String;)V + public final fun programJar (Ljava/lang/Object;)V + public final fun programJar (Lorg/gradle/api/Task;)V + public final fun programJar (Lorg/gradle/api/tasks/TaskProvider;)V + public final fun proguardFile (Ljava/lang/Object;)V + public final fun proguardFiles ([Ljava/lang/Object;)V + public final fun stripGradleApi (Z)V + public final fun systemClassesToolchain (Lorg/gradle/api/Action;)V + public final fun systemClassesToolchain (Lorg/gradle/jvm/toolchain/JavaCompiler;)V +} + +public abstract class com/gradleup/gr8/Gr8Extension { + public fun (Lorg/gradle/api/Project;)V + public final fun addShadowedVariant (Ljava/lang/Object;)V + public final fun create (Ljava/lang/String;Lorg/gradle/api/Action;)Lorg/gradle/api/provider/Provider; + public static synthetic fun create$default (Lcom/gradleup/gr8/Gr8Extension;Ljava/lang/String;Lorg/gradle/api/Action;ILjava/lang/Object;)Lorg/gradle/api/provider/Provider; + protected abstract fun getJavaToolchainService ()Lorg/gradle/jvm/toolchain/JavaToolchainService; + public final fun removeGradleApiFromApi ()V + public final fun replaceOutgoingJar (Ljava/lang/Object;)V +} + +public abstract class com/gradleup/gr8/Gr8Task : org/gradle/api/DefaultTask { + public fun ()V + public final fun classPathFiles (Ljava/lang/Object;)V + protected abstract fun getJavaToolchainService ()Lorg/gradle/jvm/toolchain/JavaToolchainService; + public final fun javaLauncher (Lorg/gradle/jvm/toolchain/JavaCompiler;)V + public final fun mapping (Ljava/io/File;)V + public final fun outputJar ()Lorg/gradle/api/provider/Provider; + public final fun outputJar (Ljava/io/File;)V + public final fun programFiles (Ljava/lang/Object;)V + public final fun proguardConfigurationFiles (Ljava/lang/Object;)V + public final fun taskAction ()V + public final fun toolchain (Lorg/gradle/api/Action;)V +} + +public abstract class com/gradleup/gr8/StripGradleApiTask : org/gradle/api/DefaultTask { + public static final field Companion Lcom/gradleup/gr8/StripGradleApiTask$Companion; + public fun ()V + public final fun gradleApiJar (Ljava/io/File;)V + public final fun gradleApiJar (Lorg/gradle/api/file/FileCollection;)V + public final fun gradleApiJar (Lorg/gradle/api/file/RegularFileProperty;)V + public final fun strippedGradleApiJar ()Lorg/gradle/api/provider/Provider; + public final fun strippedGradleApiJar (Ljava/io/File;)V + public final fun strippedGradleApiJar (Lorg/gradle/api/file/RegularFileProperty;)V + public final fun taskAction ()V +} + +public final class com/gradleup/gr8/StripGradleApiTask$Companion { + public final fun isGradleApi (Ljava/io/File;)Z +} + +public abstract interface class com/gradleup/gr8/ZipConfiguration { + public abstract fun addDirectory (Ljava/io/File;Lkotlin/jvm/functions/Function1;)V + public abstract fun addFile (Ljava/io/File;Ljava/lang/String;)V + public abstract fun addZipFile (Ljava/io/File;Lkotlin/jvm/functions/Function1;)V + public abstract fun exclude (Ljava/lang/String;)V +} + +public final class com/gradleup/gr8/ZipConfiguration$DefaultImpls { + public static synthetic fun addDirectory$default (Lcom/gradleup/gr8/ZipConfiguration;Ljava/io/File;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V + public static synthetic fun addFile$default (Lcom/gradleup/gr8/ZipConfiguration;Ljava/io/File;Ljava/lang/String;ILjava/lang/Object;)V + public static synthetic fun addZipFile$default (Lcom/gradleup/gr8/ZipConfiguration;Ljava/io/File;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V +} + +public final class com/gradleup/gr8/ZipHelper { + public static final field INSTANCE Lcom/gradleup/gr8/ZipHelper; + public final fun buildZip (Ljava/io/File;Lkotlin/jvm/functions/Function1;)V + public final fun transformJar (Ljava/io/File;Ljava/io/File;Lkotlin/jvm/functions/Function2;)V + public final fun unzipFile (Ljava/io/File;Ljava/io/File;)V + public final fun zipFolder (Ljava/io/File;Ljava/io/File;)V +} + +public final class com/gradleup/gr8/ZipHelperKt { + public static final fun copy (Ljava/util/zip/ZipEntry;Ljava/lang/String;Ljava/nio/file/attribute/FileTime;Ljava/nio/file/attribute/FileTime;Ljava/nio/file/attribute/FileTime;JJJI[BLjava/lang/String;)Ljava/util/zip/ZipEntry; + public static synthetic fun copy$default (Ljava/util/zip/ZipEntry;Ljava/lang/String;Ljava/nio/file/attribute/FileTime;Ljava/nio/file/attribute/FileTime;Ljava/nio/file/attribute/FileTime;JJJI[BLjava/lang/String;ILjava/lang/Object;)Ljava/util/zip/ZipEntry; +} + diff --git a/gr8-plugin-common/build.gradle.kts b/gr8-plugin-common/build.gradle.kts new file mode 100644 index 0000000..65305a1 --- /dev/null +++ b/gr8-plugin-common/build.gradle.kts @@ -0,0 +1,13 @@ +import com.gradleup.librarian.gradle.librarianModule + +plugins { + id("org.jetbrains.kotlin.jvm") +} + +dependencies { + compileOnly(libs.gradle.api) + implementation(libs.r8) +} + +librarianModule() + diff --git a/plugin-common/src/main/kotlin/com/gradleup/gr8/DetectDuplicates.kt b/gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/DetectDuplicates.kt similarity index 100% rename from plugin-common/src/main/kotlin/com/gradleup/gr8/DetectDuplicates.kt rename to gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/DetectDuplicates.kt diff --git a/plugin-common/src/main/kotlin/com/gradleup/gr8/EmbeddedJarTask.kt b/gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/EmbeddedJarTask.kt similarity index 100% rename from plugin-common/src/main/kotlin/com/gradleup/gr8/EmbeddedJarTask.kt rename to gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/EmbeddedJarTask.kt diff --git a/plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Configurator.kt b/gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Configurator.kt similarity index 100% rename from plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Configurator.kt rename to gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Configurator.kt diff --git a/plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Extension.kt b/gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Extension.kt similarity index 78% rename from plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Extension.kt rename to gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Extension.kt index 7490b73..80da943 100644 --- a/plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Extension.kt +++ b/gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Extension.kt @@ -2,13 +2,13 @@ package com.gradleup.gr8 import org.gradle.api.Action import org.gradle.api.Project +import org.gradle.api.artifacts.FileCollectionDependency import org.gradle.api.attributes.Bundling import org.gradle.api.attributes.Category import org.gradle.api.attributes.LibraryElements import org.gradle.api.attributes.Usage import org.gradle.api.component.AdhocComponentWithVariants import org.gradle.api.file.RegularFile -import org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency import org.gradle.api.provider.Provider import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPublication @@ -105,19 +105,28 @@ abstract class Gr8Extension( project.artifacts.add("gr8", shadowedJar) } + /** + * Removes `gradleApi()` from the `api` configuration. + * + * `gradleApi()` is added automatically by the `java-gradle-plugin` plugin but is generally not desired because: + * - the Gradle API version used to compile a plugin is different from the version used to run it (see https://github.com/gradle/gradle/issues/1835) + * - exposing Gradle API gives more work to R8 and has been seen failing due to issues like below + * + * ``` + * org/gradle/internal/impldep/META-INF/versions/15/org/bouncycastle/jcajce/provider/asymmetric/edec/SignatureSpi$EdDSA.class: + * java.lang.IllegalArgumentException: Unsupported class file major version 59 + * ``` + * + * Note: there's no public API for determining whether a dependency is actually the `gradleApi()` dependency. + * This method makes a best guess by removing all `FileCollectionDependency`. If you added `FileCollectionDependency`, + * you'll want to use something else. + */ fun removeGradleApiFromApi() { - // The java-gradle-plugin adds `gradleApi()` to the `api` implementation but it contains some JDK15 bytecode at - // org/gradle/internal/impldep/META-INF/versions/15/org/bouncycastle/jcajce/provider/asymmetric/edec/SignatureSpi$EdDSA.class: - //java.lang.IllegalArgumentException: Unsupported class file major version 59 - // So remove it val apiDependencies = project.configurations.getByName("api").dependencies - val gradleApi = apiDependencies.firstOrNull { - val targetComponentId = (it as? DefaultSelfResolvingDependency)?.targetComponentId?.toString() - targetComponentId == "Gradle API" - } - - if (gradleApi != null) { - apiDependencies.remove(gradleApi) + apiDependencies.firstOrNull { + it is FileCollectionDependency + }.let { + apiDependencies.remove(it) } } } diff --git a/plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Task.kt b/gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Task.kt similarity index 100% rename from plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Task.kt rename to gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Task.kt diff --git a/plugin-common/src/main/kotlin/com/gradleup/gr8/StripGradleApiTask.kt b/gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/StripGradleApiTask.kt similarity index 100% rename from plugin-common/src/main/kotlin/com/gradleup/gr8/StripGradleApiTask.kt rename to gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/StripGradleApiTask.kt diff --git a/plugin-common/src/main/kotlin/com/gradleup/gr8/ZipHelper.kt b/gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/ZipHelper.kt similarity index 100% rename from plugin-common/src/main/kotlin/com/gradleup/gr8/ZipHelper.kt rename to gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/ZipHelper.kt diff --git a/gr8-plugin-external/api/gr8-plugin-external.api b/gr8-plugin-external/api/gr8-plugin-external.api new file mode 100644 index 0000000..e39e3fc --- /dev/null +++ b/gr8-plugin-external/api/gr8-plugin-external.api @@ -0,0 +1,6 @@ +public class com/gradleup/gr8/Gr8Plugin : org/gradle/api/Plugin { + public fun ()V + public synthetic fun apply (Ljava/lang/Object;)V + public fun apply (Lorg/gradle/api/Project;)V +} + diff --git a/plugin-external/build.gradle.kts b/gr8-plugin-external/build.gradle.kts similarity index 62% rename from plugin-external/build.gradle.kts rename to gr8-plugin-external/build.gradle.kts index fa524fa..d268933 100644 --- a/plugin-external/build.gradle.kts +++ b/gr8-plugin-external/build.gradle.kts @@ -1,11 +1,12 @@ +import com.gradleup.librarian.gradle.librarianModule + plugins { - id("gr8.build.common") - id("gr8.build.publishing") + id("org.jetbrains.kotlin.jvm") id("java-gradle-plugin") } dependencies { - implementation(project(":plugin-common")).excludeKotlinStdlib() + implementation(project(":gr8-plugin-common")).excludeKotlinStdlib() } fun Dependency?.excludeKotlinStdlib() { @@ -16,12 +17,7 @@ fun Dependency?.excludeKotlinStdlib() { } } -val name = "Gr8 Plugin External" -val gr8Description = "The Gr8 Plugin packaged with external dependencies" - -gr8Publishing { - configurePublications(name, gr8Description) -} +librarianModule() gradlePlugin { plugins { @@ -29,8 +25,8 @@ gradlePlugin { id = "com.gradleup.gr8.external" implementationClass = "com.gradleup.gr8.Gr8Plugin" // This is required by the Gradle publish plugin - displayName = name - description = gr8Description + displayName = "Gr8 Plugin External" + description = "The Gr8 Plugin packaged with external dependencies" } } } diff --git a/plugin-external/src/main/kotlin/com/gradleup/gr8/Gr8Plugin.kt b/gr8-plugin-external/src/main/kotlin/com/gradleup/gr8/Gr8Plugin.kt similarity index 100% rename from plugin-external/src/main/kotlin/com/gradleup/gr8/Gr8Plugin.kt rename to gr8-plugin-external/src/main/kotlin/com/gradleup/gr8/Gr8Plugin.kt diff --git a/gr8-plugin/api/gr8-plugin.api b/gr8-plugin/api/gr8-plugin.api new file mode 100644 index 0000000..e39e3fc --- /dev/null +++ b/gr8-plugin/api/gr8-plugin.api @@ -0,0 +1,6 @@ +public class com/gradleup/gr8/Gr8Plugin : org/gradle/api/Plugin { + public fun ()V + public synthetic fun apply (Ljava/lang/Object;)V + public fun apply (Lorg/gradle/api/Project;)V +} + diff --git a/plugin/build.gradle.kts b/gr8-plugin/build.gradle.kts similarity index 54% rename from plugin/build.gradle.kts rename to gr8-plugin/build.gradle.kts index 275a5f4..323a641 100644 --- a/plugin/build.gradle.kts +++ b/gr8-plugin/build.gradle.kts @@ -1,6 +1,9 @@ +@file:Suppress("UnstableApiUsage") + +import com.gradleup.librarian.gradle.librarianModule + plugins { - id("gr8.build.common") - id("gr8.build.publishing") + id("org.jetbrains.kotlin.jvm") id("java-gradle-plugin") id("com.gradleup.gr8") } @@ -9,7 +12,7 @@ val shadeConfiguration: Configuration = configurations.create("shade") val classpathConfiguration: Configuration = configurations.create("gr8Classpath") dependencies { - add("shade", project(":plugin-common")) { + add("shade", project(":gr8-plugin-common")) { // Because we only allow stripping the gradleApi from the classpath, we remove exclude("dev.gradleplugins", "gradle-api") } @@ -28,9 +31,23 @@ if (true) { proguardFile("rules.pro") classPathConfiguration("gr8Classpath") stripGradleApi(true) + + systemClassesToolchain { + languageVersion.set(JavaLanguageVersion.of(11)) + } + } + + // The java-gradle-plugin adds `gradleApi()` to the `api` implementation but it contains some JDK15 bytecode at + // org/gradle/internal/impldep/META-INF/versions/15/org/bouncycastle/jcajce/provider/asymmetric/edec/SignatureSpi$EdDSA.class: + // java.lang.IllegalArgumentException: Unsupported class file major version 59 + // So remove it + val apiDependencies = project.configurations.getByName("api").dependencies + apiDependencies.firstOrNull { + it is FileCollectionDependency + }.let { + apiDependencies.remove(it) } - removeGradleApiFromApi() replaceOutgoingJar(shadowedJar) } } else { @@ -39,21 +56,16 @@ if (true) { } } -val name = "Gr8 Plugin" -val gr8description = "The Gr8 Plugin packaged with all dependencies relocated" - -gr8Publishing { - configurePublications(name, gr8description) -} gradlePlugin { plugins { create("gr8") { id = "com.gradleup.gr8" implementationClass = "com.gradleup.gr8.Gr8Plugin" // This is required by the Gradle publish plugin - displayName = name - description = gr8description + displayName = "Gr8 Plugin" + description = "The Gr8 Plugin packaged with all dependencies relocated" } } } +librarianModule() diff --git a/plugin/rules.pro b/gr8-plugin/rules.pro similarity index 85% rename from plugin/rules.pro rename to gr8-plugin/rules.pro index e825237..8e75533 100644 --- a/plugin/rules.pro +++ b/gr8-plugin/rules.pro @@ -22,3 +22,5 @@ -repackageclasses com.gradleup.gr8.relocated +-keep class com.android.tools.r8.threading.providers.blocking.ThreadingModuleBlockingProvider { *; } +-keep class com.android.tools.r8.threading.providers.singlethreaded.ThreadingModuleSingleThreadedProvider { *; } diff --git a/plugin/src/main/kotlin/com/gradleup/gr8/Gr8Plugin.kt b/gr8-plugin/src/main/kotlin/com/gradleup/gr8/Gr8Plugin.kt similarity index 100% rename from plugin/src/main/kotlin/com/gradleup/gr8/Gr8Plugin.kt rename to gr8-plugin/src/main/kotlin/com/gradleup/gr8/Gr8Plugin.kt diff --git a/gradle.properties b/gradle.properties index dcbb613..2d33552 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1 @@ org.gradle.jvmargs=-Xmx4g - -kotlin.stdlib.default.dependency=false \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..290e4cd --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,10 @@ +[libraries] +gradle-api = "dev.gradleplugins:gradle-api:6.7" +r8 = "com.android.tools:r8:8.5.35" +librarian = "com.gradleup.librarian:librarian-gradle-plugin:0.0.6" +gr8-published = "com.gradleup:gr8-plugin:0.10" +gradle-publish = "com.gradle.publish:plugin-publish-plugin:0.15.0" +kgp = "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20" +vespene = "net.mbonnin.vespene:vespene-lib:0.6.1" + +[plugins] diff --git a/gradle/repositories.gradle.kts b/gradle/repositories.gradle.kts index 8f291b5..c4be3f9 100644 --- a/gradle/repositories.gradle.kts +++ b/gradle/repositories.gradle.kts @@ -4,6 +4,9 @@ pluginManagement { mavenCentral() google() gradlePluginPortal() + maven { + url = uri("https://storage.googleapis.com/r8-releases/raw") + } } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 070cb70..1e2fbf0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/librarian.properties b/librarian.properties new file mode 100644 index 0000000..03379c9 --- /dev/null +++ b/librarian.properties @@ -0,0 +1,14 @@ +java.compatibility=8 +kotlin.compatibility=1.9.0 + +kdoc.olderVersions= + +sonatype.backend=Default + +pom.groupId=com.gradleup +pom.version=0.10.1-SNAPSHOT +pom.description=Gradle + R8 = <3 +pom.vcsUrl=https://github.com/GradleUp/gr8 +pom.developer=gr8 authors +pom.license=MIT License +pom.licenseUrl=https://raw.githubusercontent.com/gr8/GradleUp/main/LICENSE \ No newline at end of file diff --git a/plugin-common/build.gradle.kts b/plugin-common/build.gradle.kts deleted file mode 100644 index c1b21b5..0000000 --- a/plugin-common/build.gradle.kts +++ /dev/null @@ -1,20 +0,0 @@ -plugins { - id("gr8.build.common") - id("gr8.build.publishing") -} - -dependencies { - api("dev.gradleplugins:gradle-api:6.7") - implementation("net.mbonnin.r8:r8:8.3.8") -} - -val name = "Gr8 Plugin Common" -val description = "The Gr8 Plugin bytecode with no plugin declaration" - -gr8Publishing { - configurePublications(name, description) -} - -publishing.publications.create("default", MavenPublication::class.java) { - from(components.getByName("java")) -} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 6df9144..d2afb1f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,10 +1,15 @@ -pluginManagement { - includeBuild("build-logic") -} +includeBuild("build-logic") apply(from = "./gradle/repositories.gradle.kts") -include(":plugin") -include(":plugin-external") -include(":plugin-common") +include(":gr8-plugin") +include(":gr8-plugin-external") +include(":gr8-plugin-common") +/** + * We need Java <= 17 until we update the embedded gr8 + * See https://issuetracker.google.com/u/2/issues/365578411 + */ +check(JavaVersion.current() <= JavaVersion.VERSION_17) { + "This project needs to be run with Java 17 or higher (found: ${JavaVersion.current()})." +} \ No newline at end of file