From 11dc310a1b6a6ef9e27b563aa425d9a7928176bc Mon Sep 17 00:00:00 2001 From: goutamadwant Date: Thu, 18 Jun 2026 20:20:50 -0700 Subject: [PATCH] Respect build environment manifest entry setting Disable the Maven Archiver Build-Jdk-Spec default entry when archive manifest build environment entries are disabled. Add an MJAR-539 integration test covering the modular jar path and verifying build environment manifest entries stay absent. --- .../pom.xml | 49 +++++++++++++++++++ .../src/main/java/module-info.java | 21 ++++++++ .../src/main/java/myproject/HelloWorld.java | 23 +++++++++ .../verify.groovy | 40 +++++++++++++++ .../maven/plugins/jar/AbstractJarMojo.java | 1 + 5 files changed, 134 insertions(+) create mode 100644 src/it/MJAR-539-build-environment-entries/pom.xml create mode 100644 src/it/MJAR-539-build-environment-entries/src/main/java/module-info.java create mode 100644 src/it/MJAR-539-build-environment-entries/src/main/java/myproject/HelloWorld.java create mode 100644 src/it/MJAR-539-build-environment-entries/verify.groovy diff --git a/src/it/MJAR-539-build-environment-entries/pom.xml b/src/it/MJAR-539-build-environment-entries/pom.xml new file mode 100644 index 0000000..3fe15f7 --- /dev/null +++ b/src/it/MJAR-539-build-environment-entries/pom.xml @@ -0,0 +1,49 @@ + + + + 4.0.0 + org.apache.maven.plugins + mjar-539-build-environment-entries + 1.0-SNAPSHOT + jar + mjar-539-build-environment-entries + + + 11 + + + + + + org.apache.maven.plugins + maven-jar-plugin + @project.version@ + + + + false + myproject.HelloWorld + + + + + + + diff --git a/src/it/MJAR-539-build-environment-entries/src/main/java/module-info.java b/src/it/MJAR-539-build-environment-entries/src/main/java/module-info.java new file mode 100644 index 0000000..1dd5e2d --- /dev/null +++ b/src/it/MJAR-539-build-environment-entries/src/main/java/module-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +module org.apache.maven.plugins.jar.it.mjar539 { + exports myproject; +} diff --git a/src/it/MJAR-539-build-environment-entries/src/main/java/myproject/HelloWorld.java b/src/it/MJAR-539-build-environment-entries/src/main/java/myproject/HelloWorld.java new file mode 100644 index 0000000..740ba51 --- /dev/null +++ b/src/it/MJAR-539-build-environment-entries/src/main/java/myproject/HelloWorld.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package myproject; + +public class HelloWorld { + public static void main(String[] args) {} +} diff --git a/src/it/MJAR-539-build-environment-entries/verify.groovy b/src/it/MJAR-539-build-environment-entries/verify.groovy new file mode 100644 index 0000000..9b0af48 --- /dev/null +++ b/src/it/MJAR-539-build-environment-entries/verify.groovy @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.jar.*; + +File target = new File( basedir, "target" ); +assert target.exists() +assert target.isDirectory() + +File artifact = new File( target, "mjar-539-build-environment-entries-1.0-SNAPSHOT.jar" ); +assert artifact.exists() +assert artifact.isFile() + +JarFile jar = new JarFile( artifact ); +Attributes manifest = jar.getManifest().getMainAttributes(); + +assert "myproject.HelloWorld".equals( manifest.get( Attributes.Name.MAIN_CLASS ) ) +assert manifest.getValue( "Build-Jdk-Spec" ) == null +assert manifest.getValue( "Build-Tool" ) == null +assert manifest.getValue( "Build-Jdk" ) == null +assert manifest.getValue( "Build-Os" ) == null +assert manifest.getValue( "Build-Tool-Jdk-Spec" ) == null + +jar.close(); diff --git a/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java b/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java index ffb62b9..10e00af 100644 --- a/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java +++ b/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java @@ -266,6 +266,7 @@ public Path createArchive() throws MojoException { MavenArchiver archiver = new MavenArchiver(); archiver.setCreatedBy("Maven JAR Plugin", "org.apache.maven.plugins", "maven-jar-plugin"); + archiver.setBuildJdkSpecDefaultEntry(archive.getManifest().isAddBuildEnvironmentEntries()); archiver.setArchiver((JarArchiver) archivers.get(archiverName)); archiver.setOutputFile(jarFile.toFile());