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

Report or fail build when kotlin-compiler-embeddable version is overridden #5645

Closed
3flex opened this issue Dec 29, 2022 · 8 comments · Fixed by #5726
Closed

Report or fail build when kotlin-compiler-embeddable version is overridden #5645

3flex opened this issue Dec 29, 2022 · 8 comments · Fixed by #5726

Comments

@3flex
Copy link
Member

3flex commented Dec 29, 2022

Expected Behavior

detekt runs successfully using the expected version of the kotlin-compiler-embeddable dependency. If the version of the dependency is overridden in the user's build, either warn the user or fail the build, with a link to documentation explaining the issue and some ways to deal with it.

Current Behavior

This keeps coming up as an issue that detekt doesn't properly handle.

Context

#5644 #5582 #5551 #5021 #4786 #4287

@3flex 3flex changed the title Find a way to report or fail build when kotlin-compiler-embeddable version is overridden Report or fail build when kotlin-compiler-embeddable version is overridden Dec 30, 2022
@cortinico
Copy link
Member

I think this would be really valuable.

either warn the user or fail the build

Are you suggesting querying the kotlin-compiler-embeddable version at Detekt Gradle Plugin apply() type and raising a warning there?

@3flex
Copy link
Member Author

3flex commented Jan 17, 2023

That was my initial thinking.

But actually I think a more robust method is to check it in detekt-cli. We can check org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION against the expected Kotlin compiler version before starting any analysis. We just need to embed the expected Kotlin version in the JAR somewhere to query.

What do you think about that approach?

@cortinico
Copy link
Member

What do you think about that approach?

Yup that also works 👍 I'd say that firing a warning + linking to a issue/page that explains this would be the way to go

@3flex
Copy link
Member Author

3flex commented Jan 26, 2023

I'm going with a failure instead of a warning - even if the mismatched Kotlin version might work (which can happen if it's just a difference in minor version, e.g. 1.7.0 instead of 1.7.10) it will eventually end in failure if not corrected. A warning might be lost in the noise.

But 100% agree on linking to a doc page with pointers on how to correct it.

@cortinico
Copy link
Member

cortinico commented Jan 29, 2023

I'm going with a failure instead of a warning

I thought a bit about it, and maybe this ends up being too aggressive? We would be the only Gradle plugin in the ecosystem doing this. We can't expect every user to align on the Kotlin version we impose (i.e. we're not compose).

even if the mismatched Kotlin version might work

I actually think this gives us more freedom as otherwise we might be forced to release a point release whenever Kotlin releases

EDIT: typo

@3flex
Copy link
Member Author

3flex commented Jan 29, 2023

We can expect

Assume you meant "can't"?

In any case, that's not the expectation - remember that detekt has its own dependency configuration, which requires a specific Kotlin version. The project itself can use any Kotlin version it likes and detekt doesn't impose a specific version for the project.

However the project should not override detekt's dependency configuration otherwise there will be unhandled errors, or with the PR, at least there's a more useful error with a link to the docs to allow users to fix it themselves.

@cortinico
Copy link
Member

Assume you meant "can't"?

Yup that was a typo of mine.

The project itself can use any Kotlin version it likes and detekt doesn't impose a specific version for the project.

When you say the project itself you mean the runtime right? What happens if a user is applying another gradle plugin which includes a higher version of kotlin-compiler-embeddable? Are we going to fail the build for this?

@3flex
Copy link
Member Author

3flex commented Jan 31, 2023

When you say the project itself you mean the runtime right?

Any other dependency configuration except the detekt dependency configuration. detekt dependency configuration needs a specific version of kotlin-compiler-embeddable so it's available on the detekt classpath when it runs. It doesn't matter what version of Kotlin is used for any other dependency configuration.

What happens if a user is applying another gradle plugin which includes a higher version of kotlin-compiler-embeddable?

If the plugin is overriding the dependency version used in the detekt dependency configuration then yes, the build will fail. My view is that the plugin either has a bug, or is misconfigured, if that happens. Do you know of any plugins that are overriding dependencies on all dependency configurations?

The other alternative is just to give up on this approach and have the Gradle plugin use the uber jar as the dependency. That should solve things for good but has other drawbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants