Add Spring-Boot-* manifest attributes to jars and wars built with Gradle

Closes gh-16068
This commit is contained in:
Andy Wilkinson
2019-04-02 10:11:31 +01:00
parent 336af93c7e
commit 7b5f46d6e3
6 changed files with 47 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -73,10 +73,20 @@ class BootArchiveSupport {
configureExclusions();
}
void configureManifest(Jar jar, String mainClassName) {
void configureManifest(Jar jar, String mainClassName, String springBootClasses,
String springBootLib) {
Attributes attributes = jar.getManifest().getAttributes();
attributes.putIfAbsent("Main-Class", this.loaderMainClass);
attributes.putIfAbsent("Start-Class", mainClassName);
attributes.computeIfAbsent("Spring-Boot-Version",
(key) -> determineSpringBootVersion());
attributes.putIfAbsent("Spring-Boot-Classes", springBootClasses);
attributes.putIfAbsent("Spring-Boot-Lib", springBootLib);
}
private String determineSpringBootVersion() {
String implementationVersion = getClass().getPackage().getImplementationVersion();
return (implementationVersion != null) ? implementationVersion : "unknown";
}
CopyAction createCopyAction(Jar jar) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -65,7 +65,8 @@ public class BootJar extends Jar implements BootArchive {
@Override
public void copy() {
this.support.configureManifest(this, getMainClassName());
this.support.configureManifest(this, getMainClassName(), "BOOT-INF/classes/",
"BOOT-INF/lib/");
super.copy();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,7 +57,8 @@ public class BootWar extends War implements BootArchive {
@Override
public void copy() {
this.support.configureManifest(this, getMainClassName());
this.support.configureManifest(this, getMainClassName(), "WEB-INF/classes/",
"WEB-INF/lib/");
super.copy();
}