Skip to content

Conversation

@jmatsu
Copy link
Contributor

@jmatsu jmatsu commented Oct 21, 2022

For Kotlin DSL users, closureOf<Distribution> seems to be redundant. To avoid this issue, Gradle recommends to provide org.gradle.api.Action interfaces when writing Gradle plugins because Closure interfaces cannot accept Kotlin's lambdas.

However, we need use Java to provide such interfaces because Gradle 6.7 or lower do properly recognize such interface that are originally written in Groovy. ref: https://github.com/jmatsu/repro-kotlin-dsl-bug-gradle-plugin-written-in-groovy/blob/master/README.md

This PR includes the following changes.

  • Fix the matrix builds for AGP 4.2.0
  • Convert Groovy to Java only for classes that have Action interfaces.
  • Do not have any breaking changes to the current public api and user-defined configurations.

@jmatsu jmatsu force-pushed the fix/avoid_specifying_type_of_distriubtion branch from 6e1bd9d to 26fab97 Compare October 23, 2022 17:04
@jmatsu jmatsu force-pushed the fix/avoid_specifying_type_of_distriubtion branch from 364e31c to d8467c2 Compare October 25, 2022 01:53
- '3.5.1'
- '3.6.3'
- '4.1.0'
- '4.2.0'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous build couldn't handle multiple parameters for 4.2.0 properly. FYI, 4.2.0's parameters are already defined in include section and it's the correct way to add multiple parameters.

@jmatsu jmatsu marked this pull request as ready for review October 25, 2022 02:17
@@ -0,0 +1,211 @@
package com.deploygate.gradle.plugins.dsl;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are gonna use Java 🤷

@henteko henteko self-requested a review October 25, 2022 02:46
Copy link
Member

@henteko henteko left a comment

Choose a reason for hiding this comment

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

I wrote two question, please check!

result = 31 * result + (sourceFile != null ? sourceFile.hashCode() : 0);
result = 31 * result + (message != null ? message.hashCode() : 0);
result = 31 * result + (skipAssemble ? 1 : 0);
result = 31 * result + getDistribution().hashCode();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
result = 31 * result + getDistribution().hashCode();
result = 31 * result + (hasDistribution() ? getDistribution().hashCode() : 0);

Existing code returns 0 if distribution is null.
Is there any reason not to return 0?

https://github.com/DeployGate/gradle-deploygate-plugin/pull/144/files#diff-0ac52e1ba8973482bdd7896222e2135ae8c15a3b8336aadff46afc50683a3614L143

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These code are auto-generated and following the best practice in JVM world. null should be zero, otherwise should have any value.

Copy link
Member

Choose a reason for hiding this comment

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

I did not know this code was auto-generated.
Looks good!


@Nonnull
public Distribution getDistribution() {
return optionalDistribution[0];
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/DeployGate/gradle-deploygate-plugin/pull/144/files#diff-0ac52e1ba8973482bdd7896222e2135ae8c15a3b8336aadff46afc50683a3614L48
The existing code excludes empty.
The code always returns the 0th Distribution.

Is this a not problem in behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally fine. We can ignore a few rare cases because this field is only for internal use. And also, Groovy has optional chaining but Java not. That's why it's good to convert nullable to non-null.

@jmatsu jmatsu requested a review from henteko October 25, 2022 09:19
@jmatsu
Copy link
Contributor Author

jmatsu commented Oct 25, 2022

@henteko Thank you for your reviews! Could you plz check my replies?

Copy link
Member

@henteko henteko left a comment

Choose a reason for hiding this comment

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

LGTM!

result = 31 * result + (sourceFile != null ? sourceFile.hashCode() : 0);
result = 31 * result + (message != null ? message.hashCode() : 0);
result = 31 * result + (skipAssemble ? 1 : 0);
result = 31 * result + getDistribution().hashCode();
Copy link
Member

Choose a reason for hiding this comment

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

I did not know this code was auto-generated.
Looks good!

@jmatsu
Copy link
Contributor Author

jmatsu commented Oct 27, 2022

Thanks as always!

@jmatsu jmatsu merged commit b5a0630 into master Oct 27, 2022
@jmatsu jmatsu deleted the fix/avoid_specifying_type_of_distriubtion branch October 27, 2022 02:27
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.

3 participants