Support custom fat jar layouts
Allow support for custom Lyout implementations with both the Maven and Gradle plugin. Implementations of `LayoutFactory` can now be specified to allow customization of the layout. In addition a layout may now implement `CustomLoaderLayout` if it wishes to write custom loader classes. See gh-7263
This commit is contained in:
@@ -40,6 +40,7 @@ import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
|
||||
import org.springframework.boot.loader.tools.DefaultLaunchScript;
|
||||
import org.springframework.boot.loader.tools.LaunchScript;
|
||||
import org.springframework.boot.loader.tools.Layout;
|
||||
import org.springframework.boot.loader.tools.LayoutFactory;
|
||||
import org.springframework.boot.loader.tools.Layouts;
|
||||
import org.springframework.boot.loader.tools.Libraries;
|
||||
import org.springframework.boot.loader.tools.Repackager;
|
||||
@@ -129,6 +130,15 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
|
||||
@Parameter
|
||||
private LayoutType layout;
|
||||
|
||||
/**
|
||||
* The layout factory that will be used to create the executable archive if no
|
||||
* explicit layout is set. Alternative layouts implementations can be provided by 3rd
|
||||
* parties.
|
||||
* @since 1.5
|
||||
*/
|
||||
@Parameter
|
||||
private LayoutFactory layoutFactory;
|
||||
|
||||
/**
|
||||
* A list of the libraries that must be unpacked from fat jars in order to run.
|
||||
* Specify each library as a <code><dependency></code> with a
|
||||
@@ -220,7 +230,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
|
||||
}
|
||||
|
||||
private Repackager getRepackager(File source) {
|
||||
Repackager repackager = new Repackager(source);
|
||||
Repackager repackager = new Repackager(source, this.layoutFactory);
|
||||
repackager.addMainClassTimeoutWarningListener(
|
||||
new LoggingMainClassTimeoutWarningListener());
|
||||
repackager.setMainClass(this.mainClass);
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
-----
|
||||
Use a custom layout
|
||||
-----
|
||||
Dave Syer
|
||||
-----
|
||||
2016-10-30
|
||||
-----
|
||||
|
||||
Spring Boot repackages the jar file for this project using a custom layout factory
|
||||
defined in the additional jar file, provided as a dependency to the build plugin:
|
||||
|
||||
---
|
||||
<project>
|
||||
...
|
||||
<build>
|
||||
...
|
||||
<plugins>
|
||||
...
|
||||
<plugin>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>${project.artifactId}</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<layoutFactory implementation="com.example.CustomLayoutFactory">
|
||||
<customProperty>value</customProperty>
|
||||
</layoutFactory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.example</groupid>
|
||||
<artifactId>custom-layout</artifactId>
|
||||
<version>0.0.1.BUILD-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
...
|
||||
</plugin>
|
||||
...
|
||||
</plugins>
|
||||
...
|
||||
</build>
|
||||
...
|
||||
</project>
|
||||
+---
|
||||
|
||||
The layout factory is provided as an implementation of <<<LayoutFactory>>> (from
|
||||
spring-boot-loader-tools) explicitly specified in the pom. If there is only one custom
|
||||
<<<LayoutFactory>>> on the plugin classpath and it is listed in
|
||||
<<<META-INF/spring.factories>>> then it is unnecessary to explicitly set it in the
|
||||
plugin configuration.
|
||||
|
||||
Layout factories are always ignored if an explicit <<layout>> is set.
|
||||
@@ -48,6 +48,8 @@ Spring Boot Maven Plugin
|
||||
|
||||
* {{{./examples/repackage-disable-attach.html}Local repackaged artifact}}
|
||||
|
||||
* {{{./examples/custom-layout.html}Custom layout}}
|
||||
|
||||
* {{{./examples/exclude-dependency.html}Exclude a dependency}}
|
||||
|
||||
* {{{./examples/run-debug.html}Debug the application}}
|
||||
|
||||
Reference in New Issue
Block a user