Я уже несколько дней пытаюсь заставить сборку Gradle создать jar-файл Spring Boot, который будет работать. Все строится нормально, кроме одного. Gradle не помещает правильную запись основного класса в файл манифеста.mf. Там помещается:
Main-Class: org.springframework.boot.loader.JarLauncher
instead of:
Main-Class: org.springframework.boot.loader.PropertiesLauncher
в файле манифеста. Независимо от того, что я пробовал до сих пор, Gradle принимает как правильно отформатированный файл build.gradle, создаст файл манифеста.mf с той единственной записью, которая мне нужна для класса PropertiesLauncher.
Я попробовал каждый пример, который мог согласовать с Google, в моем файле build.gradle. Он собирается нормально, но отказывается добавлять правильную запись основного класса в манифест.
Если я вручную добавляю запись основного класса в файл и вставляю ее обратно в банку, все работает нормально. Моя программа запускается нормально, и все отлично. Это сборка Gradle для нескольких проектов.
Ниже приведен мой выпотрошенный build.gradle. Возможно, в нем есть что-то проприетарное, и, надеюсь, удалите ненужное. Надеюсь, здесь достаточно для анализа. Если понадобится больше, возможно, мне придется получить больше информации. Надеюсь, большая часть необходимого находится в задаче bootJar.
import java.text.SimpleDateFormat
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardCopyOption
plugins {
// id 'org.springframework.boot' version '3.2.0'
id 'application'
id 'java'
alias(libs.plugins.springBootPlugin)
// alias(libs.plugins.springDependencyManagementPlugin)
// id 'org.springframework.boot' version '3.2.0' // Apply the Spring Boot plugin
id 'io.spring.dependency-management' version '1.1.4' // Recommended for managing Spring Boot dependencies
}
application {
mainClass = 'org.springframework.boot.loader.PropertiesLauncher'
}
//mainClassName = 'org.springframework.boot.loader.PropertiesLauncher'
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
apply plugin: 'org.springframework.boot'
ext{
group = rootProject.properties.get('groupId')
// version = rootProject.properties.get('cupps.platform.version')
}
configurations {
wrapperservice
}
ext {
}
dependencies {
// The following JMX stuff does not exist on Maven anymore.
// So we get them from maven-releases on our Nexus repository
implementation 'com.sun.jmx:jmxri:1.2.1'
implementation 'com.sun.jdmk:jmxtools:1.2.1'
implementation 'javax.management:jmxremote:1.0.1_04'
}
tasks.named("compileJava") {
}
// To disable the standard 'jar' task if you only want the bootJar
jar {
enabled = false
}
// Configuring the Main Class
// https://docs.spring.io/spring-boot/docs ... main-class
tasks.named("bootJar") {
archiveFileName = "${artifactId}-${project.property('cupps.platform.version')}.jar"
println "version2: " + "${artifactId}-${project.property('cupps.platform.version')}.jar"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
//mainClassName = 'com.arinc.afd.cupps.Application' // For Spring Boot Gradle Plugin version 2.6.x and above
// mainClassName = 'org.springframework.boot.loader.PropertiesLauncher' // For Spring Boot Gradle Plugin version 2.5.x and below
exclude ('**/batik*.*')
exclude ('**/service-wrapper.zip')
// To include the properties files, conf files, and xml file, etc under the resources folder into the JAR file.
from sourceSets.main.resources
// 'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher'
manifest {
attributes (
'Start-Class' : 'com.arinc.afd.cupps.Application',
'Built-By' : "${builtBy}",
'Build-Timestamp': new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}",
'Created-By' : "${createdBy}",
'Specification-Title' : "${specTitle}",
'Specification-Vendor' : "${specVendor}",
'Specification-Version' : "${specVersion}",
'Implementation-Title' : "${implementTitle}",
'Implementation-Vendor' : "${implementVendor}",
'Implementation-Version' : "${implementVersion}",
)
}
}
I forgot to add one very important item here. I'm using Spring Boot 2.2.13.
In rely to Robert and Murrat I can use layout in this version of Spring Boot because is has been deprecated. However, I tried it anyway and the build failed immediately with the error - "Cannot set the value of read-only property 'layout' for root project 'demo' of type org.gradle.api.Project.". Layout is for Spring Boot version 1.4 or earlier I believe.