You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2023/01/26 17:25:58 UTC
[maven-jar-plugin] branch master updated: [MJAR-292] - Detect MRJAR and add manifest entry
This is an automated email from the ASF dual-hosted git repository.
sjaranowski 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 44f90d4 [MJAR-292] - Detect MRJAR and add manifest entry
44f90d4 is described below
commit 44f90d4bb3cdf064ce827f48d27fe2e5b1a27124
Author: Jorge Solórzano <jo...@gmail.com>
AuthorDate: Wed Dec 21 14:17:46 2022 +0100
[MJAR-292] - Detect MRJAR and add manifest entry
Signed-off-by: Jorge Solórzano <jo...@gmail.com>
---
.../invoker.properties | 20 ++++
src/it/MJAR-292-detect-mjar-no-versions/pom.xml | 93 +++++++++++++++++++
.../src/main/java/myproject/HelloWorld.java | 37 ++++++++
.../src/main/java/myproject/Utils.java | 32 +++++++
.../MJAR-292-detect-mjar-no-versions/verify.groovy | 26 ++++++
src/it/MJAR-292-detect-mjar/invoker.properties | 20 ++++
src/it/MJAR-292-detect-mjar/pom.xml | 101 +++++++++++++++++++++
.../src/main/java/myproject/HelloWorld.java | 37 ++++++++
.../src/main/java/myproject/Utils.java | 32 +++++++
.../src/main/java10/myproject/Utils.java | 33 +++++++
.../src/main/java9/myproject/Utils.java | 33 +++++++
src/it/MJAR-292-detect-mjar/verify.groovy | 26 ++++++
.../invoker.properties | 21 +++++
src/it/MJAR-292-disable-detect-mjar/pom.xml | 93 +++++++++++++++++++
.../src/main/java/myproject/HelloWorld.java | 37 ++++++++
.../src/main/java/myproject/Utils.java | 32 +++++++
.../src/main/java10/myproject/Utils.java | 33 +++++++
.../src/main/java9/myproject/Utils.java | 33 +++++++
src/it/MJAR-292-disable-detect-mjar/verify.groovy | 26 ++++++
.../apache/maven/plugins/jar/AbstractJarMojo.java | 43 ++++++---
20 files changed, 793 insertions(+), 15 deletions(-)
diff --git a/src/it/MJAR-292-detect-mjar-no-versions/invoker.properties b/src/it/MJAR-292-detect-mjar-no-versions/invoker.properties
new file mode 100644
index 0000000..d41b77b
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar-no-versions/invoker.properties
@@ -0,0 +1,20 @@
+# 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.
+invoker.java.version = 10+
+
+invoker.name = MJAR-292 Missing versions for MRJAR
+invoker.description = Checks the Multi-Release attribute is missing
\ No newline at end of file
diff --git a/src/it/MJAR-292-detect-mjar-no-versions/pom.xml b/src/it/MJAR-292-detect-mjar-no-versions/pom.xml
new file mode 100644
index 0000000..7a82a2d
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar-no-versions/pom.xml
@@ -0,0 +1,93 @@
+<?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-292-detect-multi-release-jar</artifactId>
+ <name>mjar-292-detect-multi-release-jar</name>
+ <description>Verifies that the multi-release jar contains the manifest entry</description>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.build.outputTimestamp>2022-12-22T13:25:58Z</project.build.outputTimestamp>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>myproject.HelloWorld</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.10.1</version>
+ <configuration>
+ <release>8</release>
+ </configuration>
+ <executions>
+ <execution>
+ <id>java9</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <release>9</release>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
+ </compileSourceRoots>
+ <multiReleaseOutput>true</multiReleaseOutput>
+ </configuration>
+ </execution>
+ <execution>
+ <id>java10</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <release>10</release>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/main/java10</compileSourceRoot>
+ </compileSourceRoots>
+ <multiReleaseOutput>true</multiReleaseOutput>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/src/it/MJAR-292-detect-mjar-no-versions/src/main/java/myproject/HelloWorld.java b/src/it/MJAR-292-detect-mjar-no-versions/src/main/java/myproject/HelloWorld.java
new file mode 100644
index 0000000..85a84d8
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar-no-versions/src/main/java/myproject/HelloWorld.java
@@ -0,0 +1,37 @@
+package myproject;
+
+/*
+ * 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.
+ */
+
+/**
+ * The classic Hello World App.
+ */
+public class HelloWorld
+{
+
+ /**
+ * Main method.
+ *
+ * @param args Not used
+ */
+ public static void main( String[] args )
+ {
+ System.out.println( new Utils().getJavaVersion() );
+ }
+}
\ No newline at end of file
diff --git a/src/it/MJAR-292-detect-mjar-no-versions/src/main/java/myproject/Utils.java b/src/it/MJAR-292-detect-mjar-no-versions/src/main/java/myproject/Utils.java
new file mode 100644
index 0000000..eea2683
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar-no-versions/src/main/java/myproject/Utils.java
@@ -0,0 +1,32 @@
+package myproject;
+
+/*
+ * 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.
+ */
+
+/**
+ * The classic Utils class.
+ */
+public class Utils
+{
+ public String getJavaVersion()
+ {
+ System.out.println("Running Java 8 (base) version");
+ return System.getProperty( "java.specification.version" );
+ }
+}
diff --git a/src/it/MJAR-292-detect-mjar-no-versions/verify.groovy b/src/it/MJAR-292-detect-mjar-no-versions/verify.groovy
new file mode 100644
index 0000000..8578151
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar-no-versions/verify.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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.*;
+
+def mrjar = new JarFile(new File(basedir,'target/mjar-292-detect-multi-release-jar-1.0-SNAPSHOT.jar'))
+def manifest = mrjar.manifest.mainAttributes
+
+assert manifest.getValue( Attributes.Name.MAIN_CLASS ) == "myproject.HelloWorld"
+assert manifest.getValue( Attributes.Name.MULTI_RELEASE ) == null
diff --git a/src/it/MJAR-292-detect-mjar/invoker.properties b/src/it/MJAR-292-detect-mjar/invoker.properties
new file mode 100644
index 0000000..dbd7d90
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar/invoker.properties
@@ -0,0 +1,20 @@
+# 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.
+invoker.java.version = 10+
+
+invoker.name = MJAR-292 Detect MRJAR
+invoker.description = Checks the Multi-Release attribute is true
\ No newline at end of file
diff --git a/src/it/MJAR-292-detect-mjar/pom.xml b/src/it/MJAR-292-detect-mjar/pom.xml
new file mode 100644
index 0000000..f3e1165
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar/pom.xml
@@ -0,0 +1,101 @@
+<?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-292-detect-multi-release-jar</artifactId>
+ <name>mjar-292-detect-multi-release-jar</name>
+ <description>Verifies that the multi-release jar contains the manifest entry</description>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.build.outputTimestamp>2022-12-22T13:25:58Z</project.build.outputTimestamp>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>myproject.HelloWorld</mainClass>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ <manifestEntries>
+ <!--
+ We override this config since we are detecting the versioned area,
+ The output JAR should contain `Multi-Release: true`
+ -->
+ <Multi-Release>false</Multi-Release>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.10.1</version>
+ <configuration>
+ <release>8</release>
+ </configuration>
+ <executions>
+ <execution>
+ <id>java9</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <release>9</release>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
+ </compileSourceRoots>
+ <multiReleaseOutput>true</multiReleaseOutput>
+ </configuration>
+ </execution>
+ <execution>
+ <id>java10</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <release>10</release>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/main/java10</compileSourceRoot>
+ </compileSourceRoots>
+ <multiReleaseOutput>true</multiReleaseOutput>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/src/it/MJAR-292-detect-mjar/src/main/java/myproject/HelloWorld.java b/src/it/MJAR-292-detect-mjar/src/main/java/myproject/HelloWorld.java
new file mode 100644
index 0000000..85a84d8
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar/src/main/java/myproject/HelloWorld.java
@@ -0,0 +1,37 @@
+package myproject;
+
+/*
+ * 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.
+ */
+
+/**
+ * The classic Hello World App.
+ */
+public class HelloWorld
+{
+
+ /**
+ * Main method.
+ *
+ * @param args Not used
+ */
+ public static void main( String[] args )
+ {
+ System.out.println( new Utils().getJavaVersion() );
+ }
+}
\ No newline at end of file
diff --git a/src/it/MJAR-292-detect-mjar/src/main/java/myproject/Utils.java b/src/it/MJAR-292-detect-mjar/src/main/java/myproject/Utils.java
new file mode 100644
index 0000000..eea2683
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar/src/main/java/myproject/Utils.java
@@ -0,0 +1,32 @@
+package myproject;
+
+/*
+ * 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.
+ */
+
+/**
+ * The classic Utils class.
+ */
+public class Utils
+{
+ public String getJavaVersion()
+ {
+ System.out.println("Running Java 8 (base) version");
+ return System.getProperty( "java.specification.version" );
+ }
+}
diff --git a/src/it/MJAR-292-detect-mjar/src/main/java10/myproject/Utils.java b/src/it/MJAR-292-detect-mjar/src/main/java10/myproject/Utils.java
new file mode 100644
index 0000000..b0bf5c7
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar/src/main/java10/myproject/Utils.java
@@ -0,0 +1,33 @@
+package myproject;
+
+/*
+ * 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.
+ */
+
+/**
+ * The classic Utils class.
+ */
+public class Utils
+{
+ public String getJavaVersion()
+ {
+ System.out.println("Running Java 10+ version");
+ Runtime.Version runtimeVersion = Runtime.version();
+ return String.valueOf( runtimeVersion.feature() );
+ }
+}
diff --git a/src/it/MJAR-292-detect-mjar/src/main/java9/myproject/Utils.java b/src/it/MJAR-292-detect-mjar/src/main/java9/myproject/Utils.java
new file mode 100644
index 0000000..613f10c
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar/src/main/java9/myproject/Utils.java
@@ -0,0 +1,33 @@
+package myproject;
+
+/*
+ * 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.
+ */
+
+/**
+ * The classic Utils class.
+ */
+public class Utils
+{
+ public String getJavaVersion()
+ {
+ System.out.println( "Running Java 9 version" );
+ Runtime.Version runtimeVersion = Runtime.version();
+ return String.valueOf( runtimeVersion.major() );
+ }
+}
diff --git a/src/it/MJAR-292-detect-mjar/verify.groovy b/src/it/MJAR-292-detect-mjar/verify.groovy
new file mode 100644
index 0000000..a06ef63
--- /dev/null
+++ b/src/it/MJAR-292-detect-mjar/verify.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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.*;
+
+def mrjar = new JarFile(new File(basedir,'target/mjar-292-detect-multi-release-jar-1.0-SNAPSHOT.jar'))
+def manifest = mrjar.manifest.mainAttributes
+
+assert manifest.getValue( Attributes.Name.MAIN_CLASS ) == "myproject.HelloWorld"
+assert manifest.getValue( Attributes.Name.MULTI_RELEASE ) == "true"
diff --git a/src/it/MJAR-292-disable-detect-mjar/invoker.properties b/src/it/MJAR-292-disable-detect-mjar/invoker.properties
new file mode 100644
index 0000000..034f5aa
--- /dev/null
+++ b/src/it/MJAR-292-disable-detect-mjar/invoker.properties
@@ -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.
+invoker.java.version = 10+
+invoker.goals = clean package -Dmaven.jar.detectMultiReleaseJar=false
+
+invoker.name = MJAR-292 MRJAR detection disabled
+invoker.description = Checks the Multi-Release attribute is not set
\ No newline at end of file
diff --git a/src/it/MJAR-292-disable-detect-mjar/pom.xml b/src/it/MJAR-292-disable-detect-mjar/pom.xml
new file mode 100644
index 0000000..7a82a2d
--- /dev/null
+++ b/src/it/MJAR-292-disable-detect-mjar/pom.xml
@@ -0,0 +1,93 @@
+<?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-292-detect-multi-release-jar</artifactId>
+ <name>mjar-292-detect-multi-release-jar</name>
+ <description>Verifies that the multi-release jar contains the manifest entry</description>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.build.outputTimestamp>2022-12-22T13:25:58Z</project.build.outputTimestamp>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>@project.version@</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>myproject.HelloWorld</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.10.1</version>
+ <configuration>
+ <release>8</release>
+ </configuration>
+ <executions>
+ <execution>
+ <id>java9</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <release>9</release>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
+ </compileSourceRoots>
+ <multiReleaseOutput>true</multiReleaseOutput>
+ </configuration>
+ </execution>
+ <execution>
+ <id>java10</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <release>10</release>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/main/java10</compileSourceRoot>
+ </compileSourceRoots>
+ <multiReleaseOutput>true</multiReleaseOutput>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
diff --git a/src/it/MJAR-292-disable-detect-mjar/src/main/java/myproject/HelloWorld.java b/src/it/MJAR-292-disable-detect-mjar/src/main/java/myproject/HelloWorld.java
new file mode 100644
index 0000000..85a84d8
--- /dev/null
+++ b/src/it/MJAR-292-disable-detect-mjar/src/main/java/myproject/HelloWorld.java
@@ -0,0 +1,37 @@
+package myproject;
+
+/*
+ * 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.
+ */
+
+/**
+ * The classic Hello World App.
+ */
+public class HelloWorld
+{
+
+ /**
+ * Main method.
+ *
+ * @param args Not used
+ */
+ public static void main( String[] args )
+ {
+ System.out.println( new Utils().getJavaVersion() );
+ }
+}
\ No newline at end of file
diff --git a/src/it/MJAR-292-disable-detect-mjar/src/main/java/myproject/Utils.java b/src/it/MJAR-292-disable-detect-mjar/src/main/java/myproject/Utils.java
new file mode 100644
index 0000000..eea2683
--- /dev/null
+++ b/src/it/MJAR-292-disable-detect-mjar/src/main/java/myproject/Utils.java
@@ -0,0 +1,32 @@
+package myproject;
+
+/*
+ * 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.
+ */
+
+/**
+ * The classic Utils class.
+ */
+public class Utils
+{
+ public String getJavaVersion()
+ {
+ System.out.println("Running Java 8 (base) version");
+ return System.getProperty( "java.specification.version" );
+ }
+}
diff --git a/src/it/MJAR-292-disable-detect-mjar/src/main/java10/myproject/Utils.java b/src/it/MJAR-292-disable-detect-mjar/src/main/java10/myproject/Utils.java
new file mode 100644
index 0000000..b0bf5c7
--- /dev/null
+++ b/src/it/MJAR-292-disable-detect-mjar/src/main/java10/myproject/Utils.java
@@ -0,0 +1,33 @@
+package myproject;
+
+/*
+ * 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.
+ */
+
+/**
+ * The classic Utils class.
+ */
+public class Utils
+{
+ public String getJavaVersion()
+ {
+ System.out.println("Running Java 10+ version");
+ Runtime.Version runtimeVersion = Runtime.version();
+ return String.valueOf( runtimeVersion.feature() );
+ }
+}
diff --git a/src/it/MJAR-292-disable-detect-mjar/src/main/java9/myproject/Utils.java b/src/it/MJAR-292-disable-detect-mjar/src/main/java9/myproject/Utils.java
new file mode 100644
index 0000000..613f10c
--- /dev/null
+++ b/src/it/MJAR-292-disable-detect-mjar/src/main/java9/myproject/Utils.java
@@ -0,0 +1,33 @@
+package myproject;
+
+/*
+ * 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.
+ */
+
+/**
+ * The classic Utils class.
+ */
+public class Utils
+{
+ public String getJavaVersion()
+ {
+ System.out.println( "Running Java 9 version" );
+ Runtime.Version runtimeVersion = Runtime.version();
+ return String.valueOf( runtimeVersion.major() );
+ }
+}
diff --git a/src/it/MJAR-292-disable-detect-mjar/verify.groovy b/src/it/MJAR-292-disable-detect-mjar/verify.groovy
new file mode 100644
index 0000000..8578151
--- /dev/null
+++ b/src/it/MJAR-292-disable-detect-mjar/verify.groovy
@@ -0,0 +1,26 @@
+/*
+ * 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.*;
+
+def mrjar = new JarFile(new File(basedir,'target/mjar-292-detect-multi-release-jar-1.0-SNAPSHOT.jar'))
+def manifest = mrjar.manifest.mainAttributes
+
+assert manifest.getValue( Attributes.Name.MAIN_CLASS ) == "myproject.HelloWorld"
+assert manifest.getValue( Attributes.Name.MULTI_RELEASE ) == null
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 d54386b..a1483ac 100644
--- a/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java
@@ -34,6 +34,7 @@ import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import java.io.File;
+import java.nio.file.FileSystems;
import java.util.Arrays;
import java.util.Map;
@@ -53,6 +54,8 @@ public abstract class AbstractJarMojo
private static final String MODULE_DESCRIPTOR_FILE_NAME = "module-info.class";
+ private static final String SEPARATOR = FileSystems.getDefault().getSeparator();
+
/**
* List of files to include. Specified as fileset patterns which are relative to the input directory whose contents
* is being packaged into the JAR.
@@ -151,6 +154,15 @@ public abstract class AbstractJarMojo
@Parameter( defaultValue = "${project.build.outputTimestamp}" )
private String outputTimestamp;
+ /**
+ * If the JAR contains the {@code META-INF/versions} directory it will be detected as a multi-release JAR file
+ * ("MRJAR"), adding the {@code Multi-Release: true} attribute to the main section of the JAR MANIFEST.MF.
+ *
+ * @since 3.3.1
+ */
+ @Parameter( property = "maven.jar.detectMultiReleaseJar", defaultValue = "true" )
+ private boolean detectMultiReleaseJar;
+
/**
* Return the specific output directory to serve as the root for the archive.
* @return get classes directory.
@@ -225,25 +237,26 @@ public abstract class AbstractJarMojo
jarContentFileSet.setIncludes( Arrays.asList( getIncludes() ) );
jarContentFileSet.setExcludes( Arrays.asList( getExcludes() ) );
- boolean containsModuleDescriptor = false;
String[] includedFiles = fileSetManager.getIncludedFiles( jarContentFileSet );
- for ( String includedFile : includedFiles )
+
+ if ( detectMultiReleaseJar && Arrays.stream( includedFiles ).anyMatch( p -> p.startsWith( "META-INF" + SEPARATOR
+ + "versions" + SEPARATOR ) ) )
{
- // May give false positives if the files is named as module descriptor
- // but is not in the root of the archive or in the versioned area
- // (and hence not actually a module descriptor).
- // That is fine since the modular Jar archiver will gracefully
- // handle such case.
- // And also such case is unlikely to happen as file ending
- // with "module-info.class" is unlikely to be included in Jar file
- // unless it is a module descriptor.
- if ( includedFile.endsWith( MODULE_DESCRIPTOR_FILE_NAME ) )
- {
- containsModuleDescriptor = true;
- break;
- }
+ getLog().debug( "Adding 'Multi-Release: true' manifest entry." );
+ archive.addManifestEntry( "Multi-Release", "true" );
}
+ // May give false positives if the files is named as module descriptor
+ // but is not in the root of the archive or in the versioned area
+ // (and hence not actually a module descriptor).
+ // That is fine since the modular Jar archiver will gracefully
+ // handle such case.
+ // And also such case is unlikely to happen as file ending
+ // with "module-info.class" is unlikely to be included in Jar file
+ // unless it is a module descriptor.
+ boolean containsModuleDescriptor =
+ Arrays.stream( includedFiles ).anyMatch( p -> p.endsWith( MODULE_DESCRIPTOR_FILE_NAME ) );
+
String archiverName = containsModuleDescriptor ? "mjar" : "jar";
MavenArchiver archiver = new MavenArchiver();