Skip to content

Support per-execution scalac configuration (#29)#147

Open
jozanek wants to merge 1 commit into
scalacenter:mainfrom
jozanek:feature/issue-29-per-execution-config
Open

Support per-execution scalac configuration (#29)#147
jozanek wants to merge 1 commit into
scalacenter:mainfrom
jozanek:feature/issue-29-per-execution-config

Conversation

@jozanek

@jozanek jozanek commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #29.

Maven lets the scala-maven-plugin <configuration> be overridden on a per-execution basis, so the compile and testCompile goals can carry different scalac options — e.g. enabling kind-projector for one but not the other.

Previously the plugin merged all executions into a single union config and applied it to both the compile and test Bloop projects, so per-goal differences were lost: Maven would compile the project fine while Bloop/Metals diverged.

What changed

initializeMojo now derives each goal's scalac options from the config Maven itself would pass to scala:compile / scala:testCompile: the plugin-level <configuration> merged with the <configuration> of the executions bound to that goal (execution-level dominating). The resulting compile/test arg lists are stashed on BloopMojo and selected per configuration when writing each Bloop project.

Notable details:

  • DOM cloningXpp3Dom.mergeXpp3Dom mutates its dominant argument, so every DOM is deep-cloned before merging. Without this, building one view (the union) would contaminate the shared Maven-model objects reused to build the compile/test splits.
  • Exact goal matching — only executions bound to compile / testCompile feed the respective split. Executions bound to unrelated goals (e.g. add-source) or no goals are excluded from the splits, but still feed the union/primary mojo, which backs Scala-version detection.
  • Effective-config fallback — a goal with no per-execution override falls back to the effective default config, so scala-maven-plugin still synthesizes its defaults (-target/-release from maven.compiler.*) and honors user properties, rather than collapsing to no options.
  • ResiliencegetScalacArgs failures are swallowed (logged at debug) so a Java-only module that merely inherits scala-maven-plugin still gets a config written, matching the previous forgiving behavior.

Scope: only scalac options are split per goal. Scala version/context, compiler jars, organization and compile setup still come from the union view, as these don't vary per goal in practice.

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.

bloop-maven: support per-execution configuration

1 participant