简体   繁体   中英

War not generated by gradle for Spring boot

I have simple spring boot application and it runs as standalone app. I started conversion to WAR using online guides.

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')
}

Initializer:

@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);
    }
}

Assembling:

c:\dev\projekty\Simulator>gradlew war
:compileJava
:processResources
:classes
:war
BUILD SUCCESSFUL
Total time: 3.96 secs

But there is no war created. Why?

The war is probably generated, just not at the place where you expect it. Add to your build script

logger.lifecycle "war.archivePath = $war.archivePath"

and it will log where you can find the WAR.

In my case, using spring-boot-gradle-plugin:2.0.0.RELEASE and Gradle 4.2 , for some reason the bootWar wasn't being triggered by gradlew war . So, I just executed the command below and the war file was generated:

./gradlew bootWar

SpringBoot disable war task. Just re-enable it in the script. I didn't like BootWar which was creating lib-provided folder and other org folder classes for traditional war deployment.

war {
    enabled= true
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM