Set implementation name and version in Gradle-built archives

Closes gh-34059
This commit is contained in:
Andy Wilkinson
2023-02-08 10:52:32 +00:00
parent d65f1cd704
commit 9378fc47a7
4 changed files with 66 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@@ -132,6 +132,42 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
.isEqualTo(this.classesPath);
assertThat(jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Lib")).isEqualTo(this.libPath);
assertThat(jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Version")).isNotNull();
assertThat(jarFile.getManifest().getMainAttributes().getValue("Implementation-Name"))
.isEqualTo(this.project.getName());
assertThat(jarFile.getManifest().getMainAttributes().getValue("Implementation-Version")).isNull();
}
}
@Test
void whenImplementationNameIsCustomizedItShouldAppearInArchiveManifest() throws IOException {
this.task.getMainClass().set("com.example.Main");
this.task.getManifest().getAttributes().put("Implementation-Name", "Customized");
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Implementation-Name"))
.isEqualTo("Customized");
}
}
@Test
void whenProjectVersionIsSetThenImplementationVersionShouldAppearInArchiveManifest() throws IOException {
this.project.setVersion("1.0.0");
this.task.getMainClass().set("com.example.Main");
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Implementation-Version")).isEqualTo("1.0.0");
}
}
@Test
void whenImplementationVersionIsCustomizedItShouldAppearInArchiveManifest() throws IOException {
this.project.setVersion("1.0.0");
this.task.getMainClass().set("com.example.Main");
this.task.getManifest().getAttributes().put("Implementation-Version", "Customized");
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
assertThat(jarFile.getManifest().getMainAttributes().getValue("Implementation-Version"))
.isEqualTo("Customized");
}
}