Skip to content

Commit 33d3d94

Browse files
[MASSEMBLY-967] IT for jar-with-dependencies with main class
1 parent b3b7866 commit 33d3d94

File tree

4 files changed

+152
-4
lines changed

4 files changed

+152
-4
lines changed

src/it/it-project-parent/pom.xml

+15-4
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,24 @@ under the License.
1818
-->
1919

2020
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2222
<modelVersion>4.0.0</modelVersion>
2323
<groupId>org.apache.maven.plugin.assembly.test</groupId>
2424
<artifactId>it-project-parent</artifactId>
2525
<packaging>pom</packaging>
2626
<version>1</version>
2727

28+
<!-- define versions of dependencies used in ITs -->
29+
<dependencyManagement>
30+
<dependencies>
31+
<dependency>
32+
<groupId>commons-io</groupId>
33+
<artifactId>commons-io</artifactId>
34+
<version>@commonsIoVersion@</version>
35+
</dependency>
36+
</dependencies>
37+
</dependencyManagement>
38+
2839
<build>
2940
<pluginManagement>
3041
<plugins>
@@ -71,14 +82,14 @@ under the License.
7182
</plugins>
7283
</pluginManagement>
7384
</build>
74-
85+
7586
<profiles>
7687
<profile>
7788
<id>testing</id>
7889
<activation>
7990
<activeByDefault>true</activeByDefault>
8091
</activation>
81-
92+
8293
<repositories>
8394
<!--
8495
<repository>
@@ -115,7 +126,7 @@ under the License.
115126
</profile>
116127
<profile>
117128
<id>live</id>
118-
129+
119130
<!-- just avoids the information injected by the testing profile, above. -->
120131
</profile>
121132
</profiles>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version='1.0'?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
21+
<project 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' xmlns='http://maven.apache.org/POM/4.0.0'>
22+
<modelVersion>4.0.0</modelVersion>
23+
<parent>
24+
<groupId>org.apache.maven.plugin.assembly.test</groupId>
25+
<artifactId>it-project-parent</artifactId>
26+
<version>1</version>
27+
</parent>
28+
29+
<artifactId>main-class-and-dependencies</artifactId>
30+
<version>1</version>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>commons-io</groupId>
35+
<artifactId>commons-io</artifactId>
36+
</dependency>
37+
</dependencies>
38+
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<artifactId>maven-assembly-plugin</artifactId>
43+
<executions>
44+
<execution>
45+
<id>assembly</id>
46+
<phase>package</phase>
47+
<goals>
48+
<goal>single</goal>
49+
</goals>
50+
<configuration>
51+
<descriptorRefs>
52+
<descriptorRef>jar-with-dependencies</descriptorRef>
53+
</descriptorRefs>
54+
<archive>
55+
<manifest>
56+
<mainClass>test.App</mainClass>
57+
</manifest>
58+
</archive>
59+
</configuration>
60+
</execution>
61+
</executions>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
</project>
66+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package test;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import org.apache.commons.io.IOUtils;
23+
24+
/**
25+
* Hello world!
26+
*
27+
*/
28+
public class App
29+
{
30+
public static void main( String[] args ) {
31+
System.out.print( "Hello World!" + IOUtils.LF );
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import java.util.jar.JarEntry
21+
import java.util.jar.JarFile
22+
import java.util.jar.Attributes
23+
24+
def expectedJarEntries = [
25+
"org/apache/commons/io/IOUtils.class",
26+
"test/App.class"
27+
]
28+
29+
File file = new File(basedir, "target/main-class-and-dependencies-1-jar-with-dependencies.jar")
30+
assert file.isFile(): "jar file is missing or a directory."
31+
32+
JarFile jarFile = new JarFile(file)
33+
expectedJarEntries.each {entryName ->
34+
JarEntry jarEntry = jarFile.getJarEntry(entryName)
35+
assert jarEntry != null: "missing jar entry: " + entryName
36+
}
37+
38+
assert "test.App" == jarFile.manifest.mainAttributes.getValue(Attributes.Name.MAIN_CLASS)

0 commit comments

Comments
 (0)