murdos opened a new issue, #582:
URL: https://github.com/apache/maven-build-cache-extension/issues/582
### Affected version
1.3.0
### Bug description
### Affected version
1.3.0 (also present in 1.2.x)
### Bug description
When a module is restored from cache, generated sources are restored on
disk, but the
directories are **not re-registered as compile / test-compile source roots**
in the
`MavenProject` model.
Plugins such as `io.github.ascopes:protobuf-maven-plugin` (and many other
code generators)
call `project.addCompileSourceRoot(...)` at runtime (here
`target/generated-sources/protobuf`).
On a cache hit, that mojo is skipped, so the source root is never added. Any
mojo running
after restoration that relies on `project.getCompileSourceRoots()` /
`getTestCompileSourceRoots()` sees an incomplete model:
- `PARTIAL_HIT`: mojos in the post-cached segment (e.g.
`maven-source-plugin:jar-no-fork`,
`maven-javadoc-plugin`, Sonar...) miss the generated sources
- forked executions restored from cache (`jetty:run`, `spring-boot:run`, ...)
#### Analysis
- At save time, `CacheControllerImpl#attachGeneratedSources` (l. 1158)
already iterates over
`project.getCompileSourceRoots()` / `getTestCompileSourceRoots()` to
decide what to attach,
but the fact that a directory *was a source root* (and of which kind) is
not recorded.
- At restore time, `CacheControllerImpl#restoreGeneratedSources` (l. 1145)
only unzips the
archive into the target directory. There is no call to
`addCompileSourceRoot` /
`addTestCompileSourceRoot` anywhere in the extension.
#### Steps to reproduce
1. Module using `io.github.ascopes:protobuf-maven-plugin:5.1.12` (goal
`generate`, default
output `target/generated-sources/protobuf`) and
`maven-source-plugin:jar-no-fork`
2. `mvn clean compile` → cache entry saved at `compile` (`cacheCompile=true`
by default)
3. `mvn verify` → `PARTIAL_HIT`, compile segment restored, `package` runs
4. The `-sources.jar` does not contain the generated protobuf classes (it
does without the
extension or with `-Dmaven.build.cache.enabled=false`)
#### Expected behavior
After restoration, the project model should be in the same state as after a
regular
execution: restored generated directories that were compile / test-compile
source roots
should be registered again.
#### Possible fix
- Record the source root kind (main / test) of each attached generated
directory in
`buildinfo.xml` (e.g. on the attached artifact / output entry)
- After unzipping in `restoreGeneratedSources`, call
`project.addCompileSourceRoot(...)` or
`project.addTestCompileSourceRoot(...)` accordingly
#### Workaround
Re-register the directory with `build-helper-maven-plugin:add-source` (and
`add-test-source`)
and force it via `executionControl/runAlways/goalsLists`, so it runs even
when the module
is restored from cache.
#### Related
- MBUILDCACHE-115 / #217 (restoration issues with the same plugin)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]