Commit c713c809 authored by Phillip Webb's avatar Phillip Webb

Polish

parent ed3df32c
...@@ -87,7 +87,8 @@ public class JacksonAutoConfiguration { ...@@ -87,7 +87,8 @@ public class JacksonAutoConfiguration {
public ObjectMapper jacksonObjectMapper() { public ObjectMapper jacksonObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
if (this.properties.isJsonSortKeys()) { if (this.properties.isJsonSortKeys()) {
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS,
true);
} }
return objectMapper; return objectMapper;
} }
......
...@@ -424,9 +424,8 @@ want the other Boot features but not this one) ...@@ -424,9 +424,8 @@ want the other Boot features but not this one)
define the executable archive. define the executable archive.
|`withJarTask` |`withJarTask`
|The name or value of the `Jar` task (defaults to all |The name or value of the `Jar` task (defaults to all tasks of type `Jar`) which is used
tasks of type `Jar`) which is used to locate the archive to to locate the archive to repackage.
repackage.
|`customConfiguration` |`customConfiguration`
|The name of the custom configuration whuch is used to populate the nested lib directory |The name of the custom configuration whuch is used to populate the nested lib directory
......
...@@ -1581,15 +1581,13 @@ details. ...@@ -1581,15 +1581,13 @@ details.
[[howto-create-an-additional-executable-jar]] [[howto-create-an-additional-executable-jar]]
=== Create an additional executable JAR === Create an additional executable JAR
If you want to use your project as a library jar for other projects to depend on, and in
addition have an executable (e.g. demo) version of it, you will want to configure the
build in a slightly different way.
If you want to use your project as a library jar for other projects to For Maven the normal JAR plugin and the Spring Boot plugin both have a ``classifier''
depend on, and in addition have an executable (e.g. demo) version of configuration that you can add to create an additional JAR. Example (using the Spring
it, you will want to configure the build in a slightly different way. Boot Starter Parent to manage the plugin versions and other configuration defaults):
For Maven the normal JAR plugin and the Spring Boot plugin both have a
"classifier" configuration that you can add to create an additional JAR.
Example (using the Spring Boot Starter Parent to manage the plugin
versions and other configuration defaults):
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim,quotes,attributes"]
---- ----
...@@ -1606,28 +1604,27 @@ versions and other configuration defaults): ...@@ -1606,28 +1604,27 @@ versions and other configuration defaults):
</build> </build>
---- ----
Two jars are produced, the default one, and an executable one using Two jars are produced, the default one, and an executable one using the Boot plugin with
the Boot plugin with classifier "exec". classifier ``exec''.
For Gradle users the steps are similar. Example: For Gradle users the steps are similar. Example:
[source,groovy,indent=0,subs="verbatim,attributes"] [source,groovy,indent=0,subs="verbatim,attributes"]
---- ----
bootRepackage { bootRepackage {
classifier = 'exec' classifier = 'exec'
} }
---- ----
[[howto-create-a-nonexecutable-jar]] [[howto-create-a-nonexecutable-jar]]
=== Create a non-executable JAR with exclusions === Create a non-executable JAR with exclusions
Often if you have an executable and a non-executable jar as build products, the executable
version will have additional configuration files that are not needed in a library jar.
E.g. the `application.yml` configuration file might excluded from the non-executable JAR.
Often if you have an executable and a non-executable jar Here's how to do that in Maven:
as build products, the executable version will have additional
configuration files that are not needed in a library jar. E.g. the
`application.yml` configuration file might excluded from the
non-executable JAR.
Here's how to do that in Maven
[source,xml,indent=0,subs="verbatim,quotes,attributes"] [source,xml,indent=0,subs="verbatim,quotes,attributes"]
---- ----
...@@ -1672,30 +1669,31 @@ Here's how to do that in Maven ...@@ -1672,30 +1669,31 @@ Here's how to do that in Maven
</build> </build>
---- ----
In Gradle you can create a new JAR archive with standard task DSL In Gradle you can create a new JAR archive with standard task DSL features, and then have
features, and then have the `bootRepackage` task depend on that one the `bootRepackage` task depend on that one using its `withJarTask` property:
using its `withJarTask` property:
[source,groovy,indent=0,subs="verbatim,attributes"] [source,groovy,indent=0,subs="verbatim,attributes"]
---- ----
jar { jar {
baseName = 'spring-boot-sample-profile' baseName = 'spring-boot-sample-profile'
version = '0.0.0' version = '0.0.0'
excludes = ['**/application.yml'] excludes = ['**/application.yml']
} }
task('execJar', type:Jar, dependsOn: 'jar') { task('execJar', type:Jar, dependsOn: 'jar') {
baseName = 'spring-boot-sample-profile' baseName = 'spring-boot-sample-profile'
version = '0.0.0' version = '0.0.0'
classifier = 'exec' classifier = 'exec'
from sourceSets.main.output from sourceSets.main.output
} }
bootRepackage { bootRepackage {
withJarTask = tasks['execJar'] withJarTask = tasks['execJar']
} }
---- ----
[[howto-remote-debug-maven-run]] [[howto-remote-debug-maven-run]]
=== Remote debug a Spring Boot application started with Maven === Remote debug a Spring Boot application started with Maven
To attach a remote debugger to a Spring Boot application started with Maven you can use To attach a remote debugger to a Spring Boot application started with Maven you can use
......
...@@ -36,26 +36,26 @@ public class FlatdirTests { ...@@ -36,26 +36,26 @@ public class FlatdirTests {
private File libs = new File("target/flatdir/lib"); private File libs = new File("target/flatdir/lib");
private static final String BOOT_VERSION = ManagedDependencies.get().find( private static final String BOOT_VERSION = ManagedDependencies.get()
"spring-boot").getVersion(); .find("spring-boot").getVersion();
@Before @Before
public void init() { public void init() {
if (libs.exists()) { if (this.libs.exists()) {
FileSystemUtils.deleteRecursively(libs); FileSystemUtils.deleteRecursively(this.libs);
} }
} }
@Test @Test
public void flatdir() throws Exception { public void flatdir() throws Exception {
project = new ProjectCreator().createProject("flatdir"); this.project = new ProjectCreator().createProject("flatdir");
if (!libs.exists()) { if (!this.libs.exists()) {
libs.mkdirs(); this.libs.mkdirs();
} }
FileCopyUtils.copy(new File("src/test/resources/foo.jar"), FileCopyUtils.copy(new File("src/test/resources/foo.jar"), new File(this.libs,
new File(libs, "foo-1.0.0.jar")); "foo-1.0.0.jar"));
project.newBuild().forTasks("build").withArguments( this.project.newBuild().forTasks("build")
"-PbootVersion=" + BOOT_VERSION, "--stacktrace").run(); .withArguments("-PbootVersion=" + BOOT_VERSION, "--stacktrace").run();
} }
} }
...@@ -49,12 +49,10 @@ public class ApplyExcludeRules implements Action<Configuration> { ...@@ -49,12 +49,10 @@ public class ApplyExcludeRules implements Action<Configuration> {
if (!VersionManagedDependencies.CONFIGURATION.equals(configuration.getName())) { if (!VersionManagedDependencies.CONFIGURATION.equals(configuration.getName())) {
configuration.getIncoming().beforeResolve( configuration.getIncoming().beforeResolve(
new Action<ResolvableDependencies>() { new Action<ResolvableDependencies>() {
@Override @Override
public void execute(ResolvableDependencies resolvableDependencies) { public void execute(ResolvableDependencies resolvableDependencies) {
resolvableDependencies.getDependencies().all( resolvableDependencies.getDependencies().all(
new Action<Dependency>() { new Action<Dependency>() {
@Override @Override
public void execute(Dependency dependency) { public void execute(Dependency dependency) {
applyExcludeRules(dependency); applyExcludeRules(dependency);
...@@ -72,11 +70,12 @@ public class ApplyExcludeRules implements Action<Configuration> { ...@@ -72,11 +70,12 @@ public class ApplyExcludeRules implements Action<Configuration> {
} }
private void applyExcludeRules(ModuleDependency dependency) { private void applyExcludeRules(ModuleDependency dependency) {
ManagedDependencies managedDependencies = versionManagedDependencies.getManagedDependencies(); ManagedDependencies managedDependencies = versionManagedDependencies
.getManagedDependencies();
// flat directory repositories do not have groups // flat directory repositories do not have groups
if (dependency.getGroup() != null) { if (dependency.getGroup() != null) {
org.springframework.boot.dependency.tools.Dependency managedDependency = managedDependencies.find( org.springframework.boot.dependency.tools.Dependency managedDependency = managedDependencies
dependency.getGroup(), dependency.getName()); .find(dependency.getGroup(), dependency.getName());
if (managedDependency != null) { if (managedDependency != null) {
for (Exclusion exclusion : managedDependency.getExclusions()) { for (Exclusion exclusion : managedDependency.getExclusions()) {
addExcludeRule(dependency, exclusion); addExcludeRule(dependency, exclusion);
...@@ -109,8 +108,8 @@ public class ApplyExcludeRules implements Action<Configuration> { ...@@ -109,8 +108,8 @@ public class ApplyExcludeRules implements Action<Configuration> {
private boolean isStarter(ModuleDependency dependency) { private boolean isStarter(ModuleDependency dependency) {
return (dependency.getGroup() != null return (dependency.getGroup() != null
&& dependency.getGroup().equals("org.springframework.boot") && dependency.getName().startsWith( && dependency.getGroup().equals("org.springframework.boot") && dependency
"spring-boot-starter")); .getName().startsWith("spring-boot-starter"));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment