战争不是由 gradle 为 Spring 启动生成的

Leo*_*rak 3 java spring gradle spring-boot

我有简单的 Spring Boot 应用程序,它作为独立应用程序运行。我开始使用在线指南转换为 WAR。

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'

bootRun {
    addResources = true
}

war {
    baseName = 'simulator'
    version =  '1.0.0'
}

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-freemarker")
    compile group: 'org.freemarker', name: 'freemarker', version: '2.3.23'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)

初始化程序:

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

组装:

c:\dev\projekty\Simulator>gradlew war
:compileJava
:processResources
:classes
:war
BUILD SUCCESSFUL
Total time: 3.96 secs
Run Code Online (Sandbox Code Playgroud)

但是没有战争。为什么?

Ita*_*tto 6

就我而言,由于某种原因,使用spring-boot-gradle-plugin:2.0.0.RELEASEand不是由. 所以,我只是执行了下面的命令并生成了war文件:Gradle 4.2bootWargradlew war

./gradlew bootWar
Run Code Online (Sandbox Code Playgroud)


des*_*ori 5

SpringBoot 禁用战争任务。只需在脚本中重新启用它。我不喜欢 BootWar,它为传统的战争部署创建 lib 提供的文件夹和其他组织文件夹类。

war {
    enabled= true
}
Run Code Online (Sandbox Code Playgroud)