This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jar-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new df1257c  Respect build environment manifest entry setting (#544)
df1257c is described below

commit df1257c1a48d30fe731aeef6d3cb562de9719eaa
Author: Goutam Adwant <[email protected]>
AuthorDate: Thu Jul 2 04:34:28 2026 -0700

    Respect build environment manifest entry setting (#544)
    
    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.
---
 src/it/MJAR-539-build-environment-entries/pom.xml  | 49 ++++++++++++++++++++++
 .../src/main/java/module-info.java                 | 21 ++++++++++
 .../src/main/java/myproject/HelloWorld.java        | 23 ++++++++++
 .../verify.groovy                                  | 40 ++++++++++++++++++
 .../apache/maven/plugins/jar/AbstractJarMojo.java  |  1 +
 5 files changed, 134 insertions(+)

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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins</groupId>
+  <artifactId>mjar-539-build-environment-entries</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+  <name>mjar-539-build-environment-entries</name>
+
+  <properties>
+    <maven.compiler.release>11</maven.compiler.release>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <archive>
+            <manifest>
+              <addBuildEnvironmentEntries>false</addBuildEnvironmentEntries>
+              <mainClass>myproject.HelloWorld</mainClass>
+            </manifest>
+          </archive>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
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 abstract class AbstractJarMojo implements 
org.apache.maven.api.plugin.Moj
 
         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());
 

Reply via email to