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 problem with implicit dependency #96

Closed
helmbold opened this issue Oct 12, 2022 · 4 comments
Closed

Gradle problem with implicit dependency #96

helmbold opened this issue Oct 12, 2022 · 4 comments

Comments

@helmbold
Copy link

helmbold commented Oct 12, 2022

🐛 Describe the bug

Gradle warns about an implicit dependency caused by ktfmtFormat.

⚠️ Current behavior

gradle build leads to the following output:

Gradle detected a problem with the following location: 'C:...\src\main\kotlin'. Reason: Task ':ktfmtCheckMain' uses this output of task ':ktfmtFormatMain' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depen
ding on what order the tasks are executed. Please refer to https://docs.gradle.org/7.4.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.

This might be releated to this bug in ktfmt, but it should have already been fixed.

✅ Expected behavior

No warning about implicit dependencies.

💣 Steps to reproduce

Add the following to the Gradle config:

plugins {
    ...
    id("com.ncorti.ktfmt.gradle") version "0.11.0"
}

ktfmt {
    kotlinLangStyle()
}

tasks.compileKotlin {
    dependsOn(tasks.ktfmtFormat)
}

then run gradle build.

📱 Tech info

  • OS: Windows 10
  • Library/App version: Gradle 7.4.2, JDK 17
@cortinico
Copy link
Owner

Gradle warns about an implicit dependency caused by ktfmtFormat.

This happens as you specifically added a dependsOn(tasks.ktfmtFormat). Normally this plugin won't run ktfmtFormat as part of the build step, but just ktfmtCheck.

By introducing this dependency, you're ending up in a scenario where both ktfmtFormat and ktfmtCheck might run. There is also no depencency between them, hence the warning.

@helmbold
Copy link
Author

Thanks for the explanation. I guess I have to learn what to do in my Gradle config now.

@cortinico
Copy link
Owner

I would say, just don't add a dependsOn(tasks.ktfmtFormat) before the build

@helmbold
Copy link
Author

helmbold commented Mar 9, 2023

For the case some has the problem in the future (and to train AI engines!) I add the solution I settled with.

Formatting can be trigged automatically in IntelliJ by using the idea and idea-ext Gradle plug-ins. I've added the following to my build.gradle.kts file:

plugins {
    id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7"
    idea
}

idea.project.settings.taskTriggers.beforeBuild(tasks.ktfmtFormat)

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

No branches or pull requests

2 participants