File tree Expand file tree Collapse file tree 6 files changed +30
-9
lines changed
spring-boot-docs/src/main/asciidoc
spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle
spring-boot-loader-tools/src
main/java/org/springframework/boot/loader/tools
spring-boot-maven-plugin/src
main/java/org/springframework/boot/maven Expand file tree Collapse file tree 6 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -563,6 +563,9 @@ springBoot {
563
563
}
564
564
----
565
565
566
+ If there is only one custom `LayoutFactory` on the build classpath and
567
+ it is listed in `META-INF/spring.factories` then it is unnecessary to
568
+ explicitly set it in the `springBoot` configuration.
566
569
567
570
[[build-tool-plugins-understanding-the-gradle-plugin]]
568
571
=== Understanding how the Gradle plugin works
Original file line number Diff line number Diff line change 26
26
import org .gradle .api .plugins .JavaPlugin ;
27
27
28
28
import org .springframework .boot .gradle .buildinfo .BuildInfo ;
29
- import org .springframework .boot .loader .tools .DefaultLayoutFactory ;
30
29
import org .springframework .boot .loader .tools .Layout ;
31
30
import org .springframework .boot .loader .tools .LayoutFactory ;
32
31
import org .springframework .boot .loader .tools .LayoutType ;
32
+ import org .springframework .boot .loader .tools .Layouts ;
33
33
34
34
/**
35
35
* Gradle DSL Extension for 'Spring Boot'. Most of the time Spring Boot can guess the
@@ -96,7 +96,7 @@ public class SpringBootPluginExtension {
96
96
/**
97
97
* The layout factory to use to convert a layout type into an actual layout.
98
98
*/
99
- LayoutFactory layoutFactory = new DefaultLayoutFactory ();
99
+ LayoutFactory layoutFactory = Layouts . getDefaultLayoutFactory ();
100
100
101
101
/**
102
102
* Libraries that must be unpacked from fat jars in order to run. Use Strings in the
Original file line number Diff line number Diff line change 21
21
import java .util .Collections ;
22
22
import java .util .HashMap ;
23
23
import java .util .HashSet ;
24
+ import java .util .List ;
24
25
import java .util .Map ;
25
26
import java .util .Set ;
26
27
28
+ import org .springframework .core .io .support .SpringFactoriesLoader ;
29
+
27
30
/**
28
31
* Common {@link Layout}s.
29
32
*
@@ -47,7 +50,22 @@ private Layouts() {
47
50
* @return a {@link Layout}
48
51
*/
49
52
public static Layout forFile (File file ) {
50
- return new DefaultLayoutFactory ().getLayout (LayoutType .forFile (file ));
53
+ return Layouts .getDefaultLayoutFactory ().getLayout (LayoutType .forFile (file ));
54
+ }
55
+
56
+ /**
57
+ * Gets a default layout factory, trying first to find a unique one in spring
58
+ * factories, and then falling back to {@link DefaultLayoutFactory} if there isn't
59
+ * one.
60
+ * @return the default layout factory
61
+ */
62
+ public static LayoutFactory getDefaultLayoutFactory () {
63
+ List <LayoutFactory > factories = SpringFactoriesLoader
64
+ .loadFactories (LayoutFactory .class , null );
65
+ if (factories .size () == 1 ) {
66
+ return factories .get (0 );
67
+ }
68
+ return new DefaultLayoutFactory ();
51
69
}
52
70
53
71
/**
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 41
41
import org .apache .maven .shared .artifact .filter .collection .ScopeFilter ;
42
42
43
43
import org .springframework .boot .loader .tools .DefaultLaunchScript ;
44
- import org .springframework .boot .loader .tools .DefaultLayoutFactory ;
45
44
import org .springframework .boot .loader .tools .LaunchScript ;
46
45
import org .springframework .boot .loader .tools .LayoutFactory ;
47
46
import org .springframework .boot .loader .tools .LayoutType ;
47
+ import org .springframework .boot .loader .tools .Layouts ;
48
48
import org .springframework .boot .loader .tools .Libraries ;
49
49
import org .springframework .boot .loader .tools .Repackager ;
50
50
@@ -139,7 +139,7 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
139
139
* @since 1.0
140
140
*/
141
141
@ Parameter
142
- private LayoutFactory layoutFactory = new DefaultLayoutFactory ();
142
+ private LayoutFactory layoutFactory = Layouts . getDefaultLayoutFactory ();
143
143
144
144
/**
145
145
* A list of the libraries that must be unpacked from fat jars in order to run.
Original file line number Diff line number Diff line change 49
49
---
50
50
51
51
The layout is provided as an implementation of <<LayoutFactory>>
52
- (from spring-boot-loader-tools) explicitly specified in the pom.
53
-
52
+ (from spring-boot-loader-tools) explicitly specified in the pom. If
53
+ there is only one custom `LayoutFactory` on the plugin classpath and
54
+ it is listed in `META-INF/spring.factories` then it is unnecessary
55
+ to explicitly set it in the plugin configuration.
54
56
55
57
56
58
You can’t perform that action at this time.
0 commit comments