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

Gradle 8.0 #2860

Closed
wants to merge 9 commits into from
Closed

Gradle 8.0 #2860

wants to merge 9 commits into from

Conversation

Goooler
Copy link
Contributor

@Goooler Goooler commented Feb 14, 2023

@Goooler Goooler marked this pull request as draft February 14, 2023 06:58
@Goooler
Copy link
Contributor Author

Goooler commented Feb 14, 2023

https://github.com/Kotlin/dokka/actions/runs/4171267730/jobs/7221031783

* Where:
Build file '/home/runner/work/dokka/dokka/kotlin-analysis/build.gradle.kts' line: 3

* What went wrong:
An exception occurred applying plugin request [id: 'com.github.johnrengelman.shadow', version: '7.1.2']
> Failed to apply plugin class 'com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin'.
   > You can't map a property that does not exist: propertyName=classifier

This issue of Shadow has been filed at GradleUp/shadow#820.

@Goooler
Copy link
Contributor Author

Goooler commented Feb 14, 2023

Jar:classifier had been removed from Gradle 8, need to migrate to archiveClassifier, just bumping Shadow plugin in buildSrc.

https://docs.gradle.org/7.6/dsl/org.gradle.api.tasks.bundling.Jar.html#org.gradle.api.tasks.bundling.Jar:classifier

@Goooler
Copy link
Contributor Author

Goooler commented Feb 14, 2023

https://github.com/Kotlin/dokka/actions/runs/4171517091/jobs/7221535291

* Exception is:
java.lang.NoSuchMethodError: org.gradle.api.internal.tasks.AbstractTaskDependency: method 'void <init>()' not found
    at org.jetbrains.dokka.gradle.TaskDependencyInternalWithAdditions.<init>(TaskDependencyInternalWithAdditions.kt:14)
    at org.jetbrains.dokka.gradle.TaskDependencyInternalWithAdditionsKt.plus(TaskDependencyInternalWithAdditions.kt:9)
    at org.jetbrains.dokka.gradle.DokkaMultiModuleTask.getTaskDependencies(DokkaMultiModuleTask.kt:45)
    at org.jetbrains.dokka.gradle.DokkaMultiModuleTask_Decorated.getTaskDependencies(Unknown Source)
    at org.jetbrains.dokka.gradle.DokkaMultiModuleTask.getTaskDependencies(DokkaMultiModuleTask.kt:18)
    at org.gradle.execution.plan.LocalTaskNode.getDependencies(LocalTaskNode.java:147)
    at org.gradle.execution.plan.LocalTaskNode.resolveDependencies(LocalTaskNode.java:121)
    at org.gradle.execution.plan.DefaultExecutionPlan.discoverNodeRelationships(DefaultExecutionPlan.java:184)

@atyrin
Copy link
Contributor

atyrin commented Feb 14, 2023

https://github.com/Kotlin/dokka/actions/runs/4171517091/jobs/7221535291

This failure is from the example project and requires the updated version of Dokka (1.8.10, not released yet)

@Goooler
Copy link
Contributor Author

Goooler commented Feb 14, 2023

Thanks, I'll continue some work after 1.8.10 released.

@Goooler
Copy link
Contributor Author

Goooler commented Mar 6, 2023

@aSemy apiVersion overrides not working after applying kotlin-dsl?

Comment on lines +26 to +32
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
apiVersion.set(KotlinVersion.fromVersion("1.4"))
languageVersion.set(KotlinVersion.fromVersion("1.4"))
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

hey @Goooler, thanks for the ping

Gradle 8 bumped the Kotlin language level to 1.8

Also, the kotlin-dsl plugin will automatically configure the language level (as well as other stuff), so there's no need to set it manually.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
apiVersion.set(KotlinVersion.fromVersion("1.4"))
languageVersion.set(KotlinVersion.fromVersion("1.4"))
}
}

Copy link
Contributor Author

@Goooler Goooler Mar 6, 2023

Choose a reason for hiding this comment

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

Cause there are some outdated APIs used, seems we can't elevate API level to 1.8 for now, that's why I declare the overriding here.

https://github.com/Kotlin/dokka/actions/runs/4344123199/jobs/7587028523
https://github.com/Kotlin/dokka/actions/runs/4344122470/jobs/7587025547

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah right, okay.

The deprecations look like minor things to fix

e: warnings found and -Werror specified
w: file:///home/runner/work/dokka/dokka/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/DokkaPlugin.kt:109:63 'decapitalize(): String' is deprecated. Use replaceFirstChar instead.
w: file:///home/runner/work/dokka/dokka/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/dokkaDefaultOutputDirectory.kt:11:59 'decapitalize(): String' is deprecated. Use replaceFirstChar instead.
w: file:///home/runner/work/dokka/dokka/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/kotlin/isMainSourceSet.kt:26:34 'toLowerCase(): String' is deprecated. Use lowercase() instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@aSemy aSemy Mar 8, 2023

Choose a reason for hiding this comment

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

I've been bitten by using kotlin-dsl in a plugin before, because the plugin was being used in versions of Gradle that were older than the version used to compile the plugin. I'd suggest reverting 2702 and avoiding use of kotlin-dsl in the plugin itself.

The kotlin-dsl plugin just adds some sensible defaults, removing it won't help - those defaults would have to be added back in and it would make the build config more complicated and brittle. So my guess is the problems you're referring to, that detekt/detekt#1286 solved, would be caused by mis-configuration (e.g. adding a runtime dependency on gradleApi()), or it using the Gradle embedded Kotlin. (Both of those problems seem have been resolved in newer Dekect plugin versions.)

In any case, it's not relevant to this PR.

Do I understand correctly that the old version of AGP is holding us from updating? That is, AGP 4.0.1 is not compatible with Gradle 8?

It's unclear. That's what the test failure seemed to suggest, but it doesn't make sense to me. The Android dependency shouldn't be 'aware' of the Gradle version†, so why should there be a missing class just because the Gradle version is different?

I'll do some digging today. It might be that we make DGP variants that are aware of the Gradle version, which on one hand is cool but on the other it will be a pain.

† While it is possible to publish plugins variants that are aware of the Gradle version that say "I'm only compatible with Gradle 7.6", so Gradle won't select them. But that's not the error (it would be a dependency resolution error), and AGP is older than the Gradle version that introduced this feature.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the context on kotlin-dsl! We'll keep an eye on it. So far it's not causing problems and I hope the integration tests cover it well

It's unclear. #2860 (comment), but it doesn't make sense to me.

Yeah, that's what I can't understand as well, the error is quite strange, considering the changes :( Unless AGP was using some Gradle API whch was removed/reworked

Thank you for taking a look!

Copy link
Contributor

Choose a reason for hiding this comment

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

The actual cause of the test failure was hidden in the GitHub logs. I reproduced it locally, and here's the key parts of the stacktrace:

org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'android-auto-configuration-test'.

Caused by: org.gradle.internal.event.ListenerNotificationException: Failed to notify project evaluation listener.

Caused by: java.lang.NoClassDefFoundError: org/gradle/api/plugins/MavenPlugin
	at com.android.build.gradle.internal.variant.VariantHelper.setupArchivesConfig(VariantHelper.java:47)
	at com.android.build.gradle.internal.LibraryTaskManager.createBundleTask(LibraryTaskManager.java:396)

Caused by: java.lang.ClassNotFoundException: org.gradle.api.plugins.MavenPlugin

The org.gradle.api.plugins.MavenPlugin class was moved and marked as deprecated in Gradle 7, and now it's removed in Gradle 8 gradle/gradle#22807

So yeah, Android-GP 4.0.1 isn't compatible with Gradle 8 (I also checked with 4.1.3 - same problem).

However, I think the test failure is caused by the test not creating a realistic scenario. It uses org.gradle.testfixtures.ProjectBuilder, which is intrinsically linked to the Gradle version used to build Dokka.

private val project = ProjectBuilder.builder().build().also { project ->
project.plugins.apply("com.android.library")
project.plugins.apply("org.jetbrains.kotlin.android")
project.plugins.apply("org.jetbrains.dokka")
project.extensions.configure<LibraryExtension> {
compileSdkVersion(28)
}
}

In real life that's not going to happen - Android-GP would have to use Gradle 7 or lower.

As I see it, the workaround is to re-write AndroidAutoConfigurationTest to use Gradle TestKit, which Dokka already has set up, and to specify the Gradle version to be 7 or lower for AndroidAutoConfigurationTest.

fun createGradleRunner(
vararg arguments: String,
jvmArgs: List<String> = listOf("-Xmx4G", "-XX:MaxMetaspaceSize=2G")
): GradleRunner {
return GradleRunner.create()
.withProjectDir(projectDir)
.forwardOutput()
.withJetBrainsCachedGradleVersion(versions.gradleVersion)
.withTestKitDir(File("build", "gradle-test-kit").absoluteFile)
.withArguments(
listOfNotNull(
"-Pkotlin_version=${versions.kotlinVersion}",
"-Pdokka_it_kotlin_version=${versions.kotlinVersion}",
versions.androidGradlePluginVersion?.let { androidVersion ->
"-Pdokka_it_android_gradle_plugin_version=$androidVersion"
},
* arguments
)
).run { this as DefaultGradleRunner }
.withJvmArguments(jvmArgs)
}

Copy link
Member

Choose a reason for hiding this comment

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

Nice find! It indeed doesn't look like it's Dokka's problem in this case, since we do support AGP 4.X, but AGP 4.X itself is not compatible with Gradle 8 - not Dokka's fault

Refactoring the test to utilize TestKit would be good, preferably in a separate PR. Although I'm not sure if it'll be possible to check the same things as in AndroidAutoConfigurationTest - it requires access to the configured Dokka tasks. Maybe it could be done as verify tasks inside of the test project? We actually already have an integration test for Android - Android0GradleIntegrationTest)

@IgnatBeresnev IgnatBeresnev self-requested a review March 7, 2023 23:14
@aSemy
Copy link
Contributor

aSemy commented Mar 8, 2023

An additional task for this PR: the tested Gradle versions should be updated to include Gradle 8, and possibly drop older versions?

internal object TestedVersions {
val LATEST = BuildVersions("7.4.2", "1.8.10")
/**
* All supported Gradle/Kotlin versions, including [LATEST]
*
* [Kotlin/Gradle compatibility matrix](https://docs.gradle.org/current/userguide/compatibility.html#kotlin)
*/
val ALL_SUPPORTED =
BuildVersions.permutations(
gradleVersions = listOf("6.9"),
kotlinVersions = listOf("1.7.20", "1.6.21", "1.5.31", "1.4.32"),
) + BuildVersions.permutations(
gradleVersions = listOf(*ifExhaustive("7.0", "6.1.1")),
kotlinVersions = listOf(*ifExhaustive("1.7.0", "1.6.0", "1.5.0", "1.4.0"))
) + LATEST
/**
* Supported Android/Gradle/Kotlin versions, including [LATEST]
*
* Starting with version 7, major Android Gradle Plugin versions are aligned
* with major Gradle versions, i.e AGP 7.X will only work with Gradle 7.X
*
* [AGP/Gradle compatibility matrix](https://developer.android.com/studio/releases/gradle-plugin#updating-gradle)
*/
val ANDROID =
BuildVersions.permutations(
gradleVersions = listOf("7.4.2", *ifExhaustive("7.0")),
kotlinVersions = listOf("1.7.20", "1.6.21", "1.5.31", "1.4.32"),
androidGradlePluginVersions = listOf("7.2.0")
) + BuildVersions.permutations(
gradleVersions = listOf("6.9", *ifExhaustive("6.1.1", "5.6.4")),
kotlinVersions = listOf("1.8.0", "1.7.0", "1.6.0", "1.5.0", "1.4.0"),
androidGradlePluginVersions = listOf("4.0.0", *ifExhaustive("3.6.3"))
) + LATEST
// https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-react
val KT_REACT_WRAPPER_MAPPING = mapOf(
"1.5.0" to "17.0.2-pre.204-kotlin-1.5.0",
"1.6.0" to "17.0.2-pre.280-kotlin-1.6.0",
"1.5.31" to "17.0.2-pre.265-kotlin-1.5.31",
"1.6.21" to "18.0.0-pre.332-kotlin-1.6.21",
"1.7.20" to "18.2.0-pre.391",
"1.8.0" to "18.2.0-pre.467",
"1.8.10" to "18.2.0-pre.490",
)
}

@IgnatBeresnev
Copy link
Member

An additional task for this PR: the tested Gradle versions should be updated to include Gradle 8, and possibly drop older versions?

Indeed, Gradle 8 should be added for sure 👍 *ifExhaustive stuff is pretty much useless as of now, I actually need to correct it

@Goooler
Copy link
Contributor Author

Goooler commented Apr 15, 2023

Addressing to #2960.

@Goooler Goooler closed this Apr 15, 2023
@Goooler Goooler deleted the gradle8 branch April 15, 2023 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants