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

Upgrade Gradle to 8.1.1 #4854

Merged
merged 13 commits into from
May 15, 2023
Merged

Upgrade Gradle to 8.1.1 #4854

merged 13 commits into from
May 15, 2023

Conversation

ikhoon
Copy link
Contributor

@ikhoon ikhoon commented May 2, 2023

Motivation:

Gradle 8 has been released.

Modifications:

  • In Gradle 8, dependencies can't be declared in a resolvable configuration (canBeResolved=true). gradle-scripts used resolvable configurations such as compileClasspath, runtimeClasspath to inject platform dependencies.

    // Add to resolvable configurations
    if (configuration.canBeResolved && !configuration.canBeConsumed) {
    add(configuration.name, platform(dependencyManagementProject))
    }

    * Where: Script '.../gradle/scripts/lib/common-dependencies.gradle'
    
    * What went wrong: A problem occurred configuring project ':foobar'.
    > Dependencies can not be declared against the `compileClasspath` configuration.
    

    platform dependencies should be added to non resolvable and non
    configurations. There is no workaround to set dependencies to
    resolvable configurations. So I changed common-dependencies.gradle
    to set platform dependencies to the non resolvable and non
    configurations.

    As a workaround shadedTestImplementation is newly added to declare
    dependencies while configuring shadedTest task. The original shadedTestRuntime
    extends shadedTestImplementation and is only used to resolve its dependencies.

    Related discussion: https://discuss.gradle.org/t/problem-with-compileclasspath-after-gradle-8-update/44940

  • Gradle 8 also disallows implicit dependencies between two tasks. The solution was quite simple. I added an explicit dependency for the implicit dependency with .dependsOn(...) whenever encountering the error.

Result:

You can now use Gradle 8 with gradle-scripts.

Motivation:

[Gradle 8](https://docs.gradle.org/8.0/release-notes.html) has been released.

Modifications:

- In Gradle 8, dependencies can't be declared in a resolvable
  configuration (canBeResolved=true). `gradle-scripts` used the resolvable
  configurations such as `compileClasspath`, `runtimeClasspath` to inject
  platform dependencies.
  https://github.com/line/armeria/blob/20969832640bcc0fa66edc68c531891ab35cea25/gradle/scripts/lib/common-dependencies.gradle#L180-L183
  ```
  * Where:
  Script '.../gradle/scripts/lib/common-dependencies.gradle'

  * What went wrong:
  A problem occurred configuring project ':foobar'.
  > Dependencies can not be declared against the `compileClasspath` configuration.
  ```

  `platform` dependencies should be added to non resolvable and non
  configurations. There is no workaround to set dependencies to
  resolvable configurations. So I changed `common-dependencies.gradle`
  to set platform dependencies to the non resolvable and non
  configurations.

  `shadedTestImplementation` is newly added to declare dependencies
  while configuring `shadedTest` task. The original `shadedTestRuntime`
  extends `shadedTestImplementation` and is only used to resolve its
  dependencies.

- Gradle 8 also disallows implicit dependencies between two tasks.
  The solution was quite simple. I added an explicit dependency for the
  implcit dependency with `.dependsOn(...)` whenever encounting the
  error.

Result:

You can now use Gradle 8 with `gradle-scripts`.
@ikhoon ikhoon added this to the 1.24.0 milestone May 2, 2023
@ikhoon ikhoon requested review from jrhee17, minwoox and trustin as code owners May 2, 2023 07:10
@@ -15,8 +15,6 @@ buildscript {
}
}

def managedDependencyOverrides = [] as Set
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was an unused code.

tasks.runKtlintCheckOverMainSourceSet.dependsOn(project.ext.getGenerateSourcesTask())

// `tasks.withType(KtLintCheckTask)` does not work here.
['Main', 'Test', 'Jmh'].each { name ->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

jmh module injects runKtlintCheckOverJmhSourceSet and compileJmhKotlin that tasks need explicit dependencies for generated sources from proto or thrift files.

@trustin
Copy link
Member

trustin commented May 2, 2023

Thanks for looking into this potentially very tricky issue, @ikhoon! Let me wait for the build to pass first at the moment.

group: 'Verification',
description: 'Runs the TestNG unit tests.',
dependsOn: tasks.shadedTestClasses) {
useTestNG()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gradle prohibits overriding the test engine with Test tasks.
On the other hand, the JVM Test Suite Plugin supports multiple test engines.
So the test tasks have been migrated to the new test plugin.

Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the upgrade. 🙇

gradle/scripts/lib/java-shade.gradle Outdated Show resolved Hide resolved
Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

Thank you so much, @ikhoon! This is a labor of love 💘

@@ -38,7 +38,7 @@
@SpringBootTest(classes = TestConfiguration.class)
@ActiveProfiles({ "local", "settings" })
@DirtiesContext
class ArmeriaSettingsConfigurationTest {
public class ArmeriaSettingsConfigurationTest {
Copy link
Member

Choose a reason for hiding this comment

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

Question: Why was this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ArmeriaSettingsConfigurationTest uses JUnit 4 which requires a public class.
I don't get why it wasn't detected before.

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Left a minor question but looks good to me! Thanks @ikhoon 🙇 👍 🚀

}

// Use a different JRE for testing if necessary.
if (rootProject.ext.buildJdkVersion != rootProject.ext.testJavaVersion) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question) Would it be better to pull changes from line/gradle-scripts#148 before merging this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

add(configuration.name, platform(dependencyManagementProject))
}

// Find version overrides in dependency declaration configurations
if (!configuration.canBeResolved && !configuration.canBeConsumed) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question) I'm wondering if we want to target resolvable dependencies instead (since these are the configurations which will actually be applied)

Suggested change
if (!configuration.canBeResolved && !configuration.canBeConsumed) {
if (configuration.canBeResolved && !configuration.canBeConsumed) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are three types of configurations.

  • Bucket - implementation, api ...
  • Resolvable - compileClasspath, runtimeClasspath, ...
  • Consumable - apiElement, ...

We directly added the dependencies to resolvable configurations. In particular, platform dependencies are added to each configuration here. Unfortunately, in Gradle 8, bucket styles are only allowed to add dependencies, and exceptions are raised if the dependencies are added to resolvable ones.

So I changed to add the platform dependencies to the buckets. It should be fine because they will be eventually inherited into resolvable configurations. All resolvable configurations defined in the Gradle Java plugin have at least one bucket configuration.
https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph

The only exception was shadedTestRuntime created by gradle-scripts that does not have a bucket parent. I added shadedTestImplementation as a bucket so that we inject the platform dependencies into it. As shadedTestRuntime extends shadedTestImplementation, all dependencies added to shadedTestImplementation will be visible to shadedTestRuntime.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understood the concept while reviewing the PR, but I'm not sure why I left this review 😅 Sorry about that.
In short, I understood that we can't add dependencies to a resolvable configuration 🙇

ikhoon and others added 5 commits May 9, 2023 22:35
Co-authored-by: minux <songmw725@gmail.com>
subrepo:
  subdir:   "gradle/scripts"
  merged:   "c20bc5b41"
upstream:
  origin:   "https://github.com/line/gradle-scripts"
  branch:   "main"
  commit:   "c20bc5b41"
git-subrepo:
  version:  "0.4.5"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "dbb99be"
@ikhoon
Copy link
Contributor Author

ikhoon commented May 11, 2023

All bugs encountered while upgrading Gradle 8 have been fixed. I will send a PR to line/gradle-scripts.

ikhoon added a commit to ikhoon/gradle-scripts that referenced this pull request May 11, 2023
See line/armeria#4854 for the detailed
motivation and changes.
ikhoon added a commit to line/gradle-scripts that referenced this pull request May 12, 2023
See line/armeria#4854 for the detailed
motivation and changes.
@ikhoon
Copy link
Contributor Author

ikhoon commented May 15, 2023

Thanks for reviewing. 🙇‍♂️

@ikhoon ikhoon merged commit e15c7b7 into line:main May 15, 2023
@ikhoon ikhoon deleted the gradle-8 branch May 15, 2023 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants