Skip to content

Commit 21db1f0

Browse files
committed
Migrate from Maven Archiver to standard jar tool by using the standard java.util.spi.ToolProvider API (requires Java 9+).
Files in the `classes` directories are dispatched to the `--manifest` and `--release` options, which allow additional verifications by the `jar` tool. Derive a POM for each individual JAR file as the intersection of the project model and the module-info of the JAR file. Side effects: * Remove the default `**/package.html` exclude. * Automatic use of `META-INF/MANIFEST.MF` file found in `classes` directory. * Automatic Multi-Release always enabled, unless `detectMultiReleaseJar` is set to `false`. * In a multi-module project, use Java module names as artifact names. * Whether the `--date` option is supported depends on the Java version. * Re-run the `jar` tool with the --validate operation mode if validation was not implicit.
1 parent dc09f23 commit 21db1f0

42 files changed

Lines changed: 3543 additions & 408 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@
3434
<name>Apache Maven JAR Plugin</name>
3535
<description>Builds a Java Archive (JAR) file from the compiled project classes and resources.</description>
3636

37+
<developers>
38+
<developer>
39+
<id>evenisse</id>
40+
<name>Emmanuel Venisse</name>
41+
<email>evenisse@apache.org</email>
42+
<roles>
43+
<role>Java Developer</role>
44+
</roles>
45+
</developer>
46+
<developer>
47+
<id>desruisseaux</id>
48+
<name>Martin Desruisseaux</name>
49+
<email>desruisseaux@apache.org</email>
50+
<organization>Geomatys</organization>
51+
<roles>
52+
<role>Java Developer</role>
53+
</roles>
54+
<timezone>+1</timezone>
55+
</developer>
56+
</developers>
3757
<contributors>
3858
<contributor>
3959
<name>Jerome Lacoste</name>
@@ -132,6 +152,12 @@
132152
<version>${mavenVersion}</version>
133153
<scope>provided</scope>
134154
</dependency>
155+
<dependency>
156+
<groupId>org.apache.maven</groupId>
157+
<artifactId>maven-support</artifactId>
158+
<version>${mavenVersion}</version>
159+
<scope>compile</scope>
160+
</dependency>
135161
<dependency>
136162
<groupId>org.apache.maven</groupId>
137163
<artifactId>maven-api-xml</artifactId>
@@ -209,7 +235,7 @@
209235
<!--
210236
! The manifest specification does not describe any method for writing comments into the manifest.
211237
-->
212-
<exclude>src/it/mjar-71-01/src/main/resources/META-INF/MANIFEST.MF</exclude>
238+
<exclude>src/it/mjar-71-01/src/main/my-custom-dir/some-manifest.mf</exclude>
213239
<exclude>src/it/mjar-71-02/src/main/resources/META-INF/MANIFEST.MF</exclude>
214240
</excludes>
215241
</configuration>

src/it/MJAR-260-invalid-automatic-module-name/verify.bsh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ try
4545
String[] snippets = new String[] {
4646
"[INFO] BUILD FAILURE",
4747
"[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin",
48-
"Caused by: org.apache.maven.api.plugin.MojoException: Error while assembling the JAR file.",
49-
"Caused by: org.codehaus.plexus.archiver.jar.ManifestException: Invalid automatic module name: 'in-valid.name.with.new.keyword'"
48+
"Caused by: org.apache.maven.api.plugin.MojoException: Invalid automatic module name: \"in-valid.name.with.new.keyword\"."
5049
};
5150

5251
System.out.println("\nVerifying log snippets...");

src/it/MJAR-275-reproducible-module-info/invoker.properties

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
# to you under the Apache License, Version 2.0 (the
66
# "License"); you may not use this file except in compliance
77
# with the License. You may obtain a copy of the License at
8-
#
8+
#
99
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
10+
#
1111
# Unless required by applicable law or agreed to in writing,
1212
# software distributed under the License is distributed on an
1313
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
# NOTE: Requires Java 10+ to compile the module declaration for Java 9+,
19-
# this is due that compiling the module declaration generates a
20-
# module descriptor with the JDK version on it, making it unreproducible.
21-
invoker.java.version = 10+
18+
# The --date option needed for reproducible build is available only since Java 19.
19+
invoker.java.version = 19+

src/it/MJAR-292-detect-mjar/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
</manifest>
8787
<manifestEntries>
8888
<!--
89-
We override this config since we are detecting the versioned area,
90-
The output JAR should contain `Multi-Release: true`
89+
For verifying that this entry will be overridden.
90+
If users really want to disable multi-release, they should set <detectMultiReleaseJar> to false.
9191
-->
9292
<Multi-Release>false</Multi-Release>
9393
</manifestEntries>

src/it/MJAR-292-disable-detect-mjar/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<mainClass>myproject.HelloWorld</mainClass>
8585
</manifest>
8686
</archive>
87+
<detectMultiReleaseJar>false</detectMultiReleaseJar>
8788
</configuration>
8889
</plugin>
8990
</plugins>

src/it/MJAR-30-include/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ try
6767
{
6868
String artifactName = artifactNames[i];
6969
if ( !contents.contains( artifactName ) )
70-
{
70+
{
7171
System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
7272
return false;
7373
}

src/it/MJAR-70-recreation/verify.bsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ if ( buildLog.exists() ) {
5858
int jarPluginExecutions = 0;
5959
String[] lines = buildLogContent.split( "\n" );
6060
for ( String line : lines ) {
61-
if ( line.contains( "Building jar:" ) && line.contains( "MJAR-70-recreation-1.0-SNAPSHOT.jar" ) ) {
61+
if ( line.contains( "Building JAR:" ) && line.contains( "MJAR-70-recreation-1.0-SNAPSHOT.jar" ) ) {
6262
jarPluginExecutions++;
6363
System.out.println( "Found JAR creation: " + line );
6464
}

src/it/mjar-71-01/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ under the License.
2525
<version>1.0</version>
2626
<packaging>jar</packaging>
2727
<name>it-mjar-71</name>
28-
<description>Test that the default manifest is added by default if found under target/classes. Can also be overriden.</description>
28+
<description>Test that the specified manifest is used.</description>
2929
<url>http://maven.apache.org</url>
3030

3131
<build>
@@ -36,7 +36,7 @@ under the License.
3636
<version>@project.version@</version>
3737
<configuration>
3838
<archive>
39-
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
39+
<manifestFile>src/main/my-custom-dir/some-manifest.mf</manifestFile>
4040
</archive>
4141
</configuration>
4242
</plugin>

src/it/mjar-71-01/src/main/resources/META-INF/MANIFEST.MF renamed to src/it/mjar-71-01/src/main/my-custom-dir/some-manifest.mf

File renamed without changes.

src/it/mjar-71-01/verify.groovy

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ try
5151
// Only compare files
5252
if ( entry.getName().equals( "META-INF/MANIFEST.MF" ) )
5353
{
54-
String manifest = IOUtils.toString( jar.getInputStream ( entry ) );
55-
int index = manifest.indexOf( "Archiver-Version: foobar-1.23456" );
56-
if ( index <= 0 )
57-
{
58-
System.err.println( "MANIFEST doesn't contain: 'Archiver-Version: foobar-1.23456'" );
59-
return false;
60-
}
61-
return true;
54+
String manifest = IOUtils.toString( jar.getInputStream ( entry ) );
55+
int index = manifest.indexOf( "Archiver-Version: foobar-1.23456" );
56+
if ( index <= 0 )
57+
{
58+
System.err.println( "MANIFEST doesn't contain: 'Archiver-Version: foobar-1.23456'" );
59+
return false;
60+
}
61+
return true;
6262
}
6363
}
6464
}

0 commit comments

Comments
 (0)