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

Fix class cast exception in gradle plugin main class detection logic #3435

Conversation

patrickpichler
Copy link
Contributor

@patrickpichler patrickpichler commented Aug 18, 2021

The main class detection logic in the gradle plugin always assumed that
the Main-Class attribute, set in the main jar task, is a string. This
is not always true, as it sometimes makes sense to set it to a provider
of String in order to link multiple configurations together.

The logic now tests the class of the value returned for the Main-Class
attribute and in case of an Provider<?> value, it will call the get
method. If the provider is not set, this will cause the task to fail.
The resulting object is then transformed to a String.

fixes #3396

@google-cla google-cla bot added the cla: yes label Aug 18, 2021
@patrickpichler patrickpichler force-pushed the bugfix/class-cast-exception-gradle-main-class branch from 01f556e to fe8876c Compare August 18, 2021 14:34
Copy link
Member

@chanseokoh chanseokoh left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! LGTM. Could you also update jib-gradle-plugin/CHANGELOG.md?

@patrickpichler
Copy link
Contributor Author

I've added a note to the change log :)

@patrickpichler patrickpichler force-pushed the bugfix/class-cast-exception-gradle-main-class branch 2 times, most recently from b2de760 to 93a052f Compare August 18, 2021 17:22
The main class detection logic in the gradle plugin always assumed that
the `Main-Class` attribute, set in the main jar task, is a string. This
is not always true, as it sometimes makes sense to set it to a provider
of String in order to link multiple configurations together.

The logic now tests the class of the value returned for the `Main-Class`
attribute and in case of an `Provider<?>` value, it will call the `get`
method. If the provider is not set, this will cause the task to fail.
The resulting object is then transformed to a String.

fixes GoogleContainerTools#3396
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

85.7% 85.7% Coverage
0.0% 0.0% Duplication

Copy link
Member

@chanseokoh chanseokoh left a comment

Choose a reason for hiding this comment

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

Thanks again!

@chanseokoh chanseokoh merged commit 0050ee4 into GoogleContainerTools:master Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

class org.gradle.api.internal.provider.DefaultProperty cannot be cast to class java.lang.String
3 participants