Skip to content

Commit

Permalink
feature: Add 'otp-shaded.jar' as an Maven published artifact.
Browse files Browse the repository at this point in the history
  • Loading branch information
t2gran committed Dec 10, 2024
1 parent 15c7da2 commit c90aea1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 40 deletions.
87 changes: 49 additions & 38 deletions shaded-jar/pom.xml → otp-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
<artifactId>otp-root</artifactId>
<version>2.7.0-SNAPSHOT</version>
</parent>
<artifactId>shaded-jar</artifactId>
<packaging>pom</packaging>
<artifactId>otp-shaded</artifactId>
<name>OpenTripPlanner - Shaded Jar</name>

<properties>
<maven.source>skip</maven.source>
<skipShadeJar>false</skipShadeJar>
</properties>

Expand All @@ -27,39 +25,25 @@
</dependencies>

<build>
<!-- finalName>otp-${project.version}-shaded</finalName -->
<plugins>
<!--
There used to be a dependency-plugin:copy-dependencies plugin entry here, but the
shade-plugin will explode the dependencies even if they aren't manually copied in.
-->
<plugin>
<!-- We want to create a standalone jar that can be run on the command
line. Java does not really allow this - you cannot place jars inside of jars.
You must either provide all the dependency jars to the user (usually lib/
under the directory containing the runnable jar) or explode all the jars
and repackage them into a single jar. The problem is that while class files
are nicely organized into the package namespace and should not collide, the
META-INF directories of the jars will collide. Maven's standard assembly
plugin does not account for this and will just clobber metadata. This then
causes runtime errors, particularly with Spring. Instead, we use the shade
plugin which has transformers that will for example append files of the same
name rather than overwrite them in the combined JAR. NB: Don't use a version
of the shade plugin older than 1.3.2, as it fixed MSHADE-76 (files not merged
properly if some input files are missing a terminating newline) -->
<groupId>org.apache.maven.plugins</groupId>
<!--
We want to create a standalone jar that can be run on the command line. Java does
not really allow this - you cannot place jars inside of jars. You must either
provide all the dependency jars to the user (usually lib/ under the directory
containing the runnable jar) or explode all the jars and repackage them into a
single jar. The problem is that while class files are nicely organized into the
package namespace and should not collide, the META-INF directories of the jars will
collide. Maven's standard assembly plugin does not account for this and will just
clobber metadata. This then causes runtime errors, particularly with Spring.
Instead, we use the shade plugin which has transformers that will for example
append files of the same name rather than overwrite them in the combined JAR.
-->
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<!--
We need to set the final name for two reasons:
- We want the artifact to have another name than the maven module.
It should be "otp" not "shaded-jar"
- For some odd reason the maven-shade-plugin uses the ${project.packaging}
as the fila extension. So, without it, the file name is
"otp-SNAPSHOT-shaded.pom". Changing the packaging of the project is not
what we want either.
-->
<outputFile>${project.build.directory}/otp-${project.version}-shaded.jar</outputFile>
<skip>${skipShadeJar}</skip>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<!-- exclude signatures from merged JAR to avoid invalid signature messages -->
Expand All @@ -71,12 +55,6 @@
</excludes>
</filter>
</filters>
<skip>${skipShadeJar}</skip>
<!-- The shaded JAR will not be the main artifact for the project, it will be attached
for deployment in the way source and docs are. -->
<shadedArtifactAttached>true</shadedArtifactAttached>
<!-- shadedClassifierName>shaded</shadedClassifierName -->
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
Expand Down Expand Up @@ -107,6 +85,39 @@
</execution>
</executions>
</plugin>


<!--
DISABLED PLUGINS
Turn off default plugins for package type jar. These plugins will normally run fine
even when there is no source, but print warnings in the Maven console log.
An alternative approach is to set "pom" as package-type and use the
build-helper-maven-plugin to attach the shaded jar as the main artifact. This also
has side effects. The biggest problem is that the published "pom.xml" does not indicate
that the main artifact is a jar file - it has package type pom.
-->

<!--
We would like to skip generating an empty jar file, but the maven-shade-plugin
fails if we set "skipIfEmpty=true". Not sure if this is a bug or if the
maven-shade-plugin needs the generated files/maven meta info from the jar plugin.
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
</configuration>
</plugin>
-->
<plugin>
<groupId>com.hubspot.maven.plugins</groupId>
<artifactId>prettier-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<module>raptor</module>
<module>gtfs-realtime-protobuf</module>
<module>application</module>
<module>shaded-jar</module>
<module>otp-shaded</module>
</modules>


Expand All @@ -110,6 +110,11 @@
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
</plugin>
<plugin>
<groupId>com.hubspot.maven.plugins</groupId>
<artifactId>prettier-maven-plugin</artifactId>
<version>${plugin.prettier.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down Expand Up @@ -290,7 +295,6 @@
<plugin>
<groupId>com.hubspot.maven.plugins</groupId>
<artifactId>prettier-maven-plugin</artifactId>
<version>${plugin.prettier.version}</version>
<configuration>
<skip>${plugin.prettier.skip}</skip>
<prettierJavaVersion>2.0.0</prettierJavaVersion>
Expand Down

0 comments on commit c90aea1

Please sign in to comment.