代码之家  ›  专栏  ›  技术社区  ›  Python_user

build/lib不是由gradle build生成的

  •  1
  • Python_user  · 技术社区  · 7 月前

    我正在进行马格努斯·拉尔森第二版书中的春季靴项目 gradle 8.11 .

    我有一个多项目结构,我通过运行来构建罐子 ./gradlew clean build -x test 在最上面的目录中。这将为各自子模块(子项目?)中的所有子模块生成jar build/lib 目录。

    问题是我添加了一个新的子项目 authorization-server 它使用 springboot 2.4.4 而其他项目使用 springboot 2.6.7 .

    现在,当我运行上述命令时,我没有看到任何 build/lib 子项目内的目录 授权服务器 .我把子项目包括在顶层 settings.gradle 带行的文件 include ':spring-cloud:authorization-server' .

    因此,我没有为这个子项目创建任何jar。


    不同的弹簧靴版本会成为问题吗?


    我已经被这个问题困扰了很长时间。我是刚毕业的,所以我不确定我做错了什么。请帮我解决同样的问题。

    以下是我的 settings.gradle 内部内容 授权服务器 :

    rootProject.name = 'authorization-server'
    

    以下是我的 build.gradle 内部内容 授权服务器 :

    plugins {
        // Can't upgrade to Spring Boot 2.5.x until fixes for the following issues are released:
        // 1. https://github.com/spring-projects-experimental/spring-authorization-server/issues/305
        // 2. https://github.com/spring-projects/spring-security/issues/9787
        id 'java'
        id 'org.springframework.boot' version '2.4.4'
    //    id 'io.spring.dependency-management' version '1.1.5'
        id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    }
    
    group = 'com.abc.xyz.practice.springcloud'
    version = '1.0.0-SNAPSHOT'
    sourceCompatibility = '1.8'
    
    //java {
    //    toolchain {
    //        languageVersion = JavaLanguageVersion.of(8)
    //    }
    //}
    //
    //jar {
    //    enabled = false
    //}
    
    ext {
        set('springCloudVersion', "2020.0.2")
    }
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-web'
        implementation 'org.springframework.boot:spring-boot-starter-actuator'
        implementation 'org.springframework.boot:spring-boot-starter-security'
        implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
        implementation 'org.springframework.security.experimental:spring-security-oauth2-authorization-server:0.1.0'
    
        testImplementation 'org.springframework.boot:spring-boot-starter-test'
    }
    
    dependencyManagement {
        imports {
            mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        }
    }
    
    test {
        useJUnitPlatform()
    }
    

    编辑:

    1. 我可以看到其他子文件夹,如 classes , generated 等等 授权服务器 项目-只有 libs 目录丢失。
    2. 此外,命令 ./gradlew干净构建-x测试 成功运行
    3. 其余子项目的罐子正在像往常一样生成。
    1 回复  |  直到 7 月前
        1
  •  1
  •   Roar S.    7 月前

    OP已确认以下命令构建了丢失的JAR文件:

    ./gradlew -p spring-cloud/authorization-server bootJar
    

    我无法在计算机上使用多模块Spring Boot项目重现问题,因此解决方案是添加

    tasks.named("build") {
        dependsOn("bootJar")
    }
    

    为了强制执行目标 bootJar .

    推荐文章