为什么跳过gradle war任务?

use*_*247 16 android gradle maven gradlew build.gradle

我是一个新的转换为gradle.大多数任务都很好.但是我看到战争任务总是被跳过.当我在调试模式下运行时,我看到以下日志 -

09:12:34.889 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger]:war 09:12:34.889 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter]开始执行任务' :war '09:12:34.889 [INFO] [org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter]跳过任务':war'作为任务onlyIf为false.09:12:34.889 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter]完成执行任务':war'09:12:34.889 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] :战争SKIPPED

我不确定为什么只有我是假的.我在互联网上搜索过.但我没有找到任何相关的东西.

这是我的gradle文件 -

buildscript {
    ext {
        springBootVersion = '2.0.0.M2'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'findbugs'
apply plugin: 'jacoco'

version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    jcenter()
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}

dependencies {

    compile('org.springframework.boot:spring-boot-starter')
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.retry:spring-retry:1.2.1.RELEASE")

    compile("org.springframework.data:spring-data-cassandra:2.0.0.M4")

    compile("io.reactivex.rxjava2:rxjava:2.1.1")

    //compile("javax.persistence:persistence-api:1.0.2")
    //compile("org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("com.zaxxer:HikariCP:2.6.0")

    // Test Dependencies
    testCompile("org.springframework.boot:spring-boot-starter-test")
    testCompile("org.powermock:powermock-mockito-release-full:1.6.4")
    testCompile("org.mockito:mockito-core:2.0.3-beta")
    testCompile("org.cassandraunit:cassandra-unit:3.1.3.2")
    testCompile("org.cassandraunit:cassandra-unit-spring:2.2.2.1")
    testCompile("com.h2database:h2:1.4.196")

    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:21.0'

    testImplementation 'junit:junit:4.12'
}
Run Code Online (Sandbox Code Playgroud)

这是我的项目结构的图像 -

在此输入图像描述

如果你能帮我生成一个很棒的war文件.

小智 33

试试吧

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


小智 29

我也遇到了与jar任务相同的问题,它正在跳过jar生成,因为如果你没有指定任何外部值,它将采用enabled = false的默认值.同样的解决方案适用于基于@Alexander Servetnik Enrironment的jar
: SpringBoot 2.x和gradle 4.4

jar {
    baseName = <your-jar name>
    enabled=true
}
Run Code Online (Sandbox Code Playgroud)

  • 将Spring Boot从1.x升级到2.x后,在Java Web应用程序上面临同样的问题.无法编译Dependent Gradle项目,因为JAR任务没有生成任何内容.这个解决方案对我有用. (2认同)
  • 即使明确运行 `./gradlew war` 任务也会跳过 war 文件的创建!似乎违反直觉。在 build.gradle 中设置 `war {enabled=true}` 修复了这个问题。 (2认同)