slachiewicz opened a new issue, #12678:
URL: https://github.com/apache/maven/issues/12678
The `org.apache.maven.api.plugin.testing` package was relocated to
`org.apache.maven.testing.plugin` in 4.0.0-rc-6 (`8857e0eb18`, "Deprecate
testing classes in org.apache.maven.api, add new ones in
org.apache.maven.testing"). Deprecated classes remain under the old names, so
plugins keep compiling — but `MojoExtension` only recognises the **new**
annotation types, so a plugin that has not moved its imports silently stops
working.
`findInjectMojoAttrs` returns null for the deprecated `@InjectMojo`, so the
`@Basedir` pom is never read and the mojo is handed `MojoExtension`'s built-in
`defaultModel` instead of the test project. Nothing warns; the test simply runs
against the wrong model.
In maven-jar-plugin this surfaced as:
```
JarMojoTest.jarTestEnvironment:48 expected: <foo> but was: <myGroupId>
```
`foo` is the groupId in the `@Basedir` test pom; `myGroupId` is
`MojoExtension`'s default. Bisected: passes on 4.0.0-rc-4 and 4.0.0-rc-5, fails
on rc-6. Pointing the imports at `org.apache.maven.testing.plugin` fixes it
(apache/maven-jar-plugin#573).
In maven-source-plugin the same cause made `@Basedir` and `@MojoParameter`
be ignored, producing `target/null-sources.jar` while the tests still reported
green.
There is a second, related break in the same relocation. The shim left
behind for `ProducedArtifactStub`:
```java
@Deprecated(since = "4.0.0-rc-6", forRemoval = true)
public class ProducedArtifactStub extends
org.apache.maven.testing.plugin.stubs.ProducedArtifactStub {
public ProducedArtifactStub();
}
```
is a bare no-arg subclass. Constructors are not inherited, so the
five-argument constructor the old class had is gone, and code using it no
longer compiles:
```
CompilerMojoTestCase.java:[436,21] constructor ProducedArtifactStub ...
cannot be applied to given types
required: no arguments found: String,String,<nulltype>,String,String
```
That one at least fails loudly (apache/maven-compiler-plugin#1104).
Suggestions, in rough order of value:
1. Make the deprecated annotations work, or fail loudly. If `MojoExtension`
accepted both annotation types the relocation would be transparent; if that is
not wanted, detecting a deprecated `@InjectMojo`/`@Basedir` and failing with a
message naming the new package would at least turn a silent wrong-model run
into an actionable error.
2. Give the `ProducedArtifactStub` shim the same five-argument constructor,
so the deprecated class is source-compatible for its remaining life.
3. Mention both in the release notes: "deprecated but still compiles, and no
longer functions" is a combination that costs downstream projects a debugging
session each.
Found while moving the plugins to rc-6 (apache/maven#12676).
--
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]