Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize build #22

Merged
merged 6 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions gr8-plugin-common/src/main/kotlin/com/gradleup/gr8/Gr8Extension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit nasty to hide that in here 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean? Is that a big change?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but it's totally unrelated to the commit title of "Remove DefaultSelfResolvingDependency", isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea 100% sorry about that, that repo usually doesn't get much review, I'll make sure to make cleaner commits moving on!

zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists