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: pluginJarFiles.from() can accept a Configuration directly. #1311

Merged
merged 2 commits into from
Jan 17, 2025

Conversation

autonomousapps
Copy link
Contributor

@autonomousapps autonomousapps commented Jan 16, 2025

This fixes a bug where local project spotbugs plugins aren't being built when running spotbugsMain. Here's our project structure:

// module/build.gradle.kts
plugins {
  ... java, kotlin, etc...
  id("com.github.spotbugs") version "6.1.1"
}

dependencies {
  ... etc...
  spotbugsPlugin(project(":my-spotbugs-plugin))
}
// my-spotbugs-plugin/build.gradle.kts
plugins {
  ... java, kotlin, etc...
}

dependencies {
  implementation("com.github.spotbugs:spotbugs:4.9.0")
  implementation("com.github.spotbugs:spotbugs-annotations:4.9.0")
}

And then when I run ./gradlew module:spotbugsMain, the task succeeds, despite violating the rule defined in my-spotbugs-plugin. If, however, I add this, then the task fails as expected:

// module/build.gradle.kts
tasks.withType<com.github.spotbugs.snom.SpotBugsTask>().configureEach {
  dependsOn(":my-spotbugs-plugin:jar")
}

which led me to this PR (because that should not be necessary). There were two issues, both of which I had to fix to resolve this issue. First, this idiom is unnecessary and seems to just not work:

val pluginConfiguration = project.configurations.getByName(SpotBugsPlugin.PLUGINS_CONFIG_NAME)
pluginJarFiles.from(
    project.provider { pluginConfiguration.files },
)

that can be simplified to

val pluginConfiguration = project.configurations.named(SpotBugsPlugin.PLUGINS_CONFIG_NAME)
pluginJarFiles.from(pluginConfiguration)

Note also that I've changed configurations.getByName() to configurations.named() to maintain laziness (the latter returns a Provider).

Second, I changed the task input annotation from @Internal to @Classpath. This input is not, in my opinion, internal at all, but an important part of the task input. It also just doesn't work when annotated as an internal property. I suspect some other properties are also improperly marked as internal, but I haven't attempted to confirm this.

@autonomousapps autonomousapps marked this pull request as ready for review January 16, 2025 22:42
@hazendaz
Copy link
Member

Ironically, the original author of this plugin was asking questions to gradle on internal annotation years ago, and someone else clarified in 2023. I'm not very skilled at gradle, but reading your write-up and searching around, I'm inclined to agree with you on all points.

Thanks for the work here!

@hazendaz hazendaz merged commit e1d960a into spotbugs:master Jan 17, 2025
8 checks passed
Copy link

🎉 This PR is included in version 6.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@autonomousapps autonomousapps deleted the trobalik.spotbugsPlugin branch January 17, 2025 19:34
@autonomousapps
Copy link
Contributor Author

Thank you for reviewing and releasing so quickly! Really appreciate it.

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.

2 participants