Gradle build命令构建基于SpringCloud项目,执行到某一个子项目时,提示程序包不存在

发布于 2022-09-06 22:00:19 字数 1940 浏览 13 评论 0

整个项目是基于 spring cloud

父项目的 build.gradle 配置:

group 'com.xxx.yyy'
version '0.1.0'

buildscript {
    ext {
        springBootVersion = '1.5.10.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath('se.transmode.gradle:gradle-docker:1.2')
    }
}

subprojects {
    apply plugin: 'idea'
    apply plugin: 'java'
    apply plugin: 'docker'
    apply plugin: 'org.springframework.boot'
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    
    sourceSets {
        main {
            java.srcDir "src"
        }
    }
    repositories {
        mavenCentral()
    }
    configurations {
        all*.exclude module: 'spring-boot-starter-logging'
        all*.exclude module: 'logback-classic'
    }
    dependencyManagement {
        imports {
            mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Edgware.SR3'
        }
    }
    dependencies {
        compile('org.springframework.boot:spring-boot-starter')
        compile('org.springframework.boot:spring-boot-starter-log4j2')
        compile('org.springframework.boot:spring-boot-starter-test')
        compile('com.fasterxml.jackson.dataformat:jackson-dataformat-yaml')
    }
}

子项目的配置就比较简单了
子项目1:

group 'com.xxx.yyy'
version '0.1.0'
archivesBaseName = 'prj1'

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    // ...
}

子项目2:

group 'com.xxx.yyy'
version '0.1.0'
archivesBaseName = 'prj2'

dependencies {
    compile project(":prj1")
}

在父项目目录下,执行 gradle build -x test 命令时

> Task :prj2:compileJava
ConsumerHelper.java:5: 错误: 程序包com.xxx.yyy.zzz不存在

请问这个是什么原因导致。。。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遗心遗梦遗幸福 2022-09-13 22:00:19

把主项目中的 build.gradle 内容一行一行条这个位置做测试,改了下仓库,最后终于可以了。。。

group 'com.xxx.yyy'
version '0.1.0'

buildscript {
    ext {
        springBootVersion = '1.5.10.RELEASE'
    }
    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath('se.transmode.gradle:gradle-docker:1.2')
    }
}

subprojects {
    apply plugin: 'idea'
    apply plugin: 'java'
    apply plugin: 'docker'
    apply plugin: 'org.springframework.boot'

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
    }
    configurations {
        all*.exclude module: 'spring-boot-starter-logging'
        all*.exclude module: 'logback-classic'
    }
    dependencyManagement {
        imports {
            mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Edgware.SR3'
        }
    }
    dependencies {
        compile('org.springframework.boot:spring-boot-starter')
        compile('org.springframework.boot:spring-boot-starter-log4j2')
        compile('org.springframework.boot:spring-boot-starter-test')
        compile('com.fasterxml.jackson.dataformat:jackson-dataformat-yaml')
    }
}

顺便在某些 module 下加上了

bootRepackage {
    enabled = false
}
长伴 2022-09-13 22:00:19

父项目需要新建一个 setting.gradle ,具体配置如下:

include 'sub_1', 'sub_2'

rootProject.name = "root_project"
给妤﹃绝世温柔 2022-09-13 22:00:19

我这样没有用

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文