【问题标题】:Overriding Spring Boot artifact name in Gradle 6.7在 Gradle 6.7 中覆盖 Spring Boot 工件名称
【发布时间】:2021-07-01 16:59:51
【问题描述】:

这里是 Java 8、Spring Boot 2.3.8 和 Gradle 6.7,我最后一次使用 Gradle 是在 4.x 上。

我通过以下方式使用 Gradle 创建了一个新的 Java 应用程序:

gradle init --type java-application

令我惊讶的是,而不是通常的目录结构:

projectRoot/
  src/
    main/
      java/
      resources/
    test/
      java/
      resources/
  build.gradle

它创建了这些,但嵌套在 app 目录中:

projectRoot/
  app/
    src/
      main/
        java/
        resources/
      test/
        java/
        resources/
    build.gradle

这是我的build.gradle

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

plugins {
    id 'java'
}

apply plugin: 'org.springframework.boot'

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
}

configurations {
    dev
}

dependencies {
    compileOnly 'org.projectlombok:lombok:1.18.16'
    annotationProcessor(
            'org.projectlombok:lombok:1.18.16'
            ,'org.springframework.boot:spring-boot-configuration-processor:2.3.8.RELEASE'
    )
    implementation platform('org.springframework.boot:spring-boot-dependencies:2.3.8.RELEASE')

    compile('org.springframework.boot:spring-boot-starter-web:2.3.8.RELEASE') {
        exclude module: 'spring-boot-starter-tomcat:2.3.8.RELEASE'
    }

    compile("org.liquibase:liquibase-core")

    compile(

            // standard stuff
            'ch.qos.logback:logback-classic:1.2.3'
            ,'org.slf4j:jul-to-slf4j:1.7.30'
            ,'org.apache.commons:commons-lang3:3.9'
            ,'commons-io:commons-io:2.6'
            ,'org.apache.commons:commons-text:1.8'
            ,'com.google.guava:guava:28.2-jre'
            ,'commons-beanutils:commons-beanutils-core:1.8.3'
            ,'javax.interceptor:javax.interceptor-api:3.1'

            // mysql
            ,'mysql:mysql-connector-java:8.0.19'

            // jwt/auth
            ,'com.auth0:java-jwt:3.10.0'

            // spring boot
            ,'org.springframework.boot:spring-boot-starter-actuator:2.3.8.RELEASE'
            ,'org.springframework.boot:spring-boot-starter-jetty:2.3.8.RELEASE'
            ,'org.springframework.boot:spring-boot-starter-web:2.3.8.RELEASE'
            ,'org.springframework.boot:spring-boot-starter-thymeleaf:2.3.8.RELEASE'
            ,'org.springframework.boot:spring-boot-starter-data-rest:2.3.8.RELEASE'
            ,'org.springframework.boot:spring-boot-starter-data-jpa:2.3.8.RELEASE'
            ,'org.springframework.boot:spring-boot-starter-security:2.3.8.RELEASE'

            ,'net.javacrumbs.shedlock:shedlock-spring:4.15.1'
            ,'net.javacrumbs.shedlock:shedlock-provider-jdbc:4.15.1'

            // metrics
            ,'io.micrometer:micrometer-core:1.3.5'
            ,'io.micrometer:micrometer-registry-prometheus:1.3.5'

            // sendgrid/mailer
            ,'com.sendgrid:sendgrid-java:4.6.7'

            ,'org.passay:passay:1.6.0'

    )

    testCompile(

            'junit:junit:4.13'
            ,'org.mockito:mockito-core:3.3.0'
            ,'io.codearte.jfairy:jfairy:0.5.9'
            ,'org.springframework.boot:spring-boot-starter-test:2.3.8.RELEASE'

    )

    dev('org.springframework.boot:spring-boot-devtools')

}

sourceCompatibility = 1.8
String buildName = 'my-service'

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
        }
    }
}

jar {
    archiveFileName = buildName
}

bootRun {
    if(project.hasProperty('debugMode')) {
        jvmArgs = [ "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005" ]
    }

    classpath = sourceSets.main.runtimeClasspath + configurations.dev
}

当我运行 ./gradlew clean build 时,它不再生成 /build/libs/my-service.jar 工件,而是现在生成 app/build/libs/app.jar 工件。

我的主要问题是 如何将名称从 app.jar 覆盖到 my-service.jar 但是,作为一个附带问题,我想知道 Java/Gradle 何时决定制作源代码/build 约定嵌套在 app/ 目录中。感谢您的所有帮助!

【问题讨论】:

    标签: spring-boot gradle java-8


    【解决方案1】:

    我想通了:

    tasks.bootJar {
        archiveFileName.set("my-service.jar")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 2015-09-20
      • 2021-08-01
      • 2019-11-21
      • 1970-01-01
      • 2017-12-18
      • 2013-03-30
      相关资源
      最近更新 更多