Skip to content

Commit

Permalink
[MSHADE-302] maven-shade-plugin fails to minimize JAR with Java 11, u…
Browse files Browse the repository at this point in the history
…pgrade jdependency to 2.1.1

Signed-off-by: olivier lamy <olamy@apache.org>
  • Loading branch information
olamy committed Nov 6, 2018
1 parent 1c091c7 commit 23d972b
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<dependency>
<groupId>org.vafer</groupId>
<artifactId>jdependency</artifactId>
<version>2.0</version>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
Expand Down
18 changes: 18 additions & 0 deletions src/it/mini-jar-jdk11/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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 = 11+
82 changes: 82 additions & 0 deletions src/it/mini-jar-jdk11/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?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>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.maven.plugins.shade.its</groupId>
<artifactId>shade-parent</artifactId>
<version>1.0</version>
<relativePath>../setup-parent</relativePath>
</parent>

<groupId>org.apache.maven.its.shade.mj</groupId>
<artifactId>testmini-jdk11</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>MSHADE-302</name>
<description>
Test that artifact contents can be filtered automatically to produce a mini jar compiled with jdk11 that only
contains the referenced classes.
</description>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>attach-shade</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
24 changes: 24 additions & 0 deletions src/it/mini-jar-jdk11/src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

public class Main extends junit.framework.TestCase
{
static class Nested { // Trigger MSHADE-302
}
}
54 changes: 54 additions & 0 deletions src/it/mini-jar-jdk11/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.io.*;
import java.util.jar.*;

String[] wanted =
{
"Main.class",
"Main$Nested.class",
"junit/framework/TestCase.class",
"junit/swingui/icons/error.gif",
};

String[] unwanted =
{
"junit/swingui/TestRunner.class",
};

JarFile jarFile = new JarFile( new File( basedir, "target/testmini-jdk11-1.0.jar" ) );

for ( String path : wanted )
{
if ( jarFile.getEntry( path ) == null )
{
throw new IllegalStateException( "wanted path is missing: " + path );
}
}

for ( String path : unwanted )
{
if ( jarFile.getEntry( path ) != null )
{
throw new IllegalStateException( "unwanted path is present: " + path );
}
}

jarFile.close();

0 comments on commit 23d972b

Please sign in to comment.