1

So I've been playing around with spring boot for the first time and it works wonderfully, except I can't figure out how to build a .war file to deploy to my personal server. I've read a dozen or more blogs documentation on the Spring website but I just don't get how to build the .war.

I'm using intellij, kotlin, and gradle. Any help pointing me in the right direction would be greatly appreciated.

Here is what my gradle file looks like:

import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootJar
import org.springframework.boot.gradle.tasks.bundling.BootWar

plugins {
    kotlin("plugin.jpa") version "1.2.71"
    id("org.springframework.boot") version "2.1.6.RELEASE" 
    id("io.spring.dependency-management") version "1.0.7.RELEASE"
    kotlin("jvm") version "1.2.71"
    kotlin("plugin.spring") version "1.2.71"

    war


}

apply(plugin = "io.spring.dependency-management")

the<DependencyManagementExtension>().apply {
    imports {
        mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
    }
}



. . . .

dependencies {
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-mustache")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    runtimeOnly("com.h2database:h2")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.getByName<Jar>("jar") {
    enabled = true
}

tasks.getByName<War>("war") {
    enabled = true
}

tasks.getByName<BootJar>("bootJar") {
    classifier = "boot"
    mainClassName = "com.daniel.we_adventurers"
    launchScript()

    manifest {
        attributes("Start-Class" to "com.daniel.we_adventurersn")
    }
}



tasks.getByName<BootWar>("bootWar") {
    classifier = "boot2"
    mainClassName = "com.daniel.we_adventurers"
    launchScript()

    manifest {
        attributes("Start-Class" to "com.daniel.we_adventurers")
        attributes("Main-Class" to "org.springframework.boot.loader.PropertiesLauncher")
    }

}


}
Dan Anderson
  • 1,062
  • 13
  • 26

2 Answers2

2

Assuming you've created your project using https://start.spring.io/, then simply follow the docs for creating a war archive:

https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#packaging-executable-wars

If you did not create it with https://start.spring.io/, then I suggest creating one from there and use it as a reference to update your current project.

Cisco
  • 20,972
  • 5
  • 38
  • 60
  • I am using start.spring.io (it's pretty slick). and I've tried following the instructions that you linked too. However, after I build the file there is no .war file. Just a `war/MANIFEST.MF` I've added my gradle code to me question. – Dan Anderson Jun 21 '19 at 17:59
  • 1
    What's the point of this answer if you are only going to direct them to a site for a solution? – Ojonugwa Jude Ochalifu Nov 13 '20 at 14:53
0

I know it's been a while since you asked, but also, since I came across your question, i would say your issue is most likely related to this line:

developmentOnly("org.springframework.boot:spring-boot-devtools")

Please see my answer to this other question here Spring Boot Application Deployment Issue.

It should lead you in the right direction.

SourceVisor
  • 1,868
  • 1
  • 27
  • 43