[ 
https://issues.apache.org/jira/browse/MJAR-62?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17607916#comment-17607916
 ] 

b. ohnsorg edited comment on MJAR-62 at 9/21/22 6:36 PM:
---------------------------------------------------------

maven-jar-plugin uses [MavenArchiver|https://github.com/apache/maven-archiver]. 
MavenArchiver depends on [Plexus 
Archiver|https://github.com/codehaus-plexus/plexus-archiver]. PlexusArchiver 
uses java.util.spi.ToolProvider. Instead 
https://cwiki.apache.org/confluence/display/MAVENOLD/Toolchains suggests 
(omitted some checks for brevity):

{code}
/**
 * @component
 */
private ToolchainManager toolchainManager;
 
/**
 * The current build session instance. This is used for
 * toolchain manager API calls.
 *
 * @parameter expression="${session}"
 * @required
 * @readonly
 */
private MavenSession session;
 
public void execute() {
    .....
 
    // get toolchain from context
    Toolchain tc = toolchainManager.getToolchainFromBuildContext( "jdk", 
//NOI18N
                            session );
    javadocExecutable = tc.findTool( "javadoc" ); //NOI18N
}
{code}

I assume that none of the Plexus-provided archivers supports toolchains by any 
means. This is either not a simple patch to maven-jar-plugin since it requires 
replacement of manifest generation. Or it spans across all the projects 
mentioned to put ToolchainManager down the stream.

I am a bit puzzled about the usage of MavenArchiver in maven-jar-plugin. It 
really seems necessary to invoke MavenArchiver.setArchiver to inject a 
JarArchiver…borrowed from injected map of Archiver-instances. This could be 
empty or not contain key-value-pairs for "jar" resp. "mjar". It seems a bit 
pointless to have flexible injection of an interface realized by different 
providers while using hard coded strings and casts to specific classes. Isn't 
this leaky abstraction?

Instead from maven-jar-plugin point of view I'd expect MavenArchiver to be 
ready to use without the need to know how creating/ updating JARs works under 
the hood. In addition the correct signature for the constructor of 
MavenArchiver should be Supplier<JarArchiver>. (MavenArchiver seems to throw 
NPE in case setArchiver is not invoked. Unless there is some convention that 
injects/ sets archiver.)

No matter how there should be an either-or type picking either classic Plexus 
way or wrapping Toolchain's jar command into something that JarArchiver can 
control. Luckily JarArchiver extends direct ZIP management (of the JDK/ JRE 
that runs Maven). Now I'm quite sure why nobody dared to put toolchain support 
into Plexus archiver or provide it as a sidechain.

https://github.com/codehaus-plexus/plexus-archiver/issues/238


was (Author: b.ohnsorg):
maven-jar-plugin uses [MavenArchiver|https://github.com/apache/maven-archiver]. 
MavenArchiver depends on [Plexus 
Archiver|https://github.com/codehaus-plexus/plexus-archiver]. PlexusArchiver 
uses java.util.spi.ToolProvider. Instead 
https://cwiki.apache.org/confluence/display/MAVENOLD/Toolchains suggests 
(omitted some checks for brevity):

{code}
/**
 * @component
 */
private ToolchainManager toolchainManager;
 
/**
 * The current build session instance. This is used for
 * toolchain manager API calls.
 *
 * @parameter expression="${session}"
 * @required
 * @readonly
 */
private MavenSession session;
 
public void execute() {
    .....
 
    // get toolchain from context
    Toolchain tc = toolchainManager.getToolchainFromBuildContext( "jdk", 
//NOI18N
                            session );
    javadocExecutable = tc.findTool( "javadoc" ); //NOI18N
}
{code}

I assume that none of the Plexus-provided archivers supports toolchains by any 
means. This is either not a simple patch to maven-jar-plugin since it requires 
replacement of manifest generation. Or it spans across all the projects 
mentioned to put ToolchainManager down the stream.

I am a bit puzzled about the usage of MavenArchiver in maven-jar-plugin. It 
really seems necessary to invoke MavenArchiver.setArchiver to inject a 
JarArchiver…borrowed from injected map of Archiver-instances. This could be 
empty or not contain key-value-pairs for "jar" resp. "mjar". It seems a bit 
pointless to have flexible injection of an interface realized by different 
providers while using hard coded strings and casts to specific classes. Isn't 
this leaky abstraction?

Instead from maven-jar-plugin point of view I'd expect MavenArchiver to be 
ready to use without the need to know how creating/ updating JARs works under 
the hood. In addition the correct signature for the constructor of 
MavenArchiver should be Supplier<JarArchiver>. (MavenArchiver seems to throw 
NPE in case setArchiver is not invoked. Unless there is some convention that 
injects/ sets archiver.)

No matter how there should be an either-or type picking either classic Plexus 
way or wrapping Toolchain's jar command into something that JarArchiver can 
control. Luckily JarArchiver extends direct ZIP management (of the JDK/ JRE 
that runs Maven). Now I'm quite sure why nobody dared to put toolchain support 
into Plexus archiver or provide it as a sidechain.

> Build-Jdk in Manifest.mf does not reflect which compiler version actually 
> compiled the classes in the jar
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: MJAR-62
>                 URL: https://issues.apache.org/jira/browse/MJAR-62
>             Project: Maven JAR Plugin
>          Issue Type: Bug
>            Reporter: Stefan Magnus Landrø
>            Priority: Major
>         Attachments: example-app.zip
>
>
> Manifest.mf does not reflect the version of the compiler that built the jar, 
> but defaults to the version that maven runs under:  Build-Jdk: 
> ${java.version}.
> I believe this makes users uncertain of which compiler was actually used to 
> build the classes.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to