【问题标题】:War not generated by gradle for Spring bootgradle 没有为 Spring boot 生成战争
【发布时间】:2017-12-03 04:23:29
【问题描述】:

我有一个简单的 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')
}

初始化器:

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

组装:

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

但是没有创造战争。为什么?

【问题讨论】:

  • gradlew build 怎么样。
  • 是什么让你认为没有创造战争?你在哪里找的?输出表明战争任务已执行,所以战争应该在build/distributions/
  • 我在 build\libs\knz-simulator-1.0.0.war 中发现了一场战争。这是目标战吗?
  • Build 包含以下目录:classes、libs、resources、tmp。顶层目录中没有 target 或 dist 目录。
  • 取决于您如何配置war 任务和项目。默认情况下,war插件添加的war任务的war应该在build/distributions/,但可能是spring boot重新配置了这个。你可以在你的构建脚本中输出war的目标路径,看看它是在哪里生成的。

标签: java spring spring-boot gradle


【解决方案1】:

在我的例子中,使用spring-boot-gradle-plugin:2.0.0.RELEASEGradle 4.2,由于某种原因bootWar 没有被gradlew war 触发。所以,我只是执行了下面的命令,生成了war文件:

./gradlew bootWar

【讨论】:

    【解决方案2】:

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

    war {
        enabled= true
    }
    

    【讨论】:

      【解决方案3】:

      war 可能已生成,只是不在您期望的位置。添加到您的构建脚本中

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

      它会记录您可以找到 WAR 的位置。

      【讨论】:

      • 模拟器>gradlew build war.archivePath = Simulator\build\libs\simulator-1.0.0.war。奇怪的路径。
      • 为什么你认为这是一条奇怪的路,你会期待什么?
      • 我正在寻找一些目标或 dist 目录。 Libs 在我看来就像是在打包之前放置库的中间目录。
      • 确实如此。正如我所说,war 插件添加的war 任务的默认路径是build/distributions/。所以一定是有什么东西改变了它。我猜它是 spring boot 插件,因为它对战争产生了最终结果。但是我不知道spring boot,所以不知道。
      猜你喜欢
      • 2017-12-21
      • 2014-12-31
      • 1970-01-01
      • 2020-02-26
      • 2018-03-04
      • 2019-03-23
      • 2022-11-10
      • 2019-02-13
      • 2020-06-18
      相关资源
      最近更新 更多