GradleCN / GradleSide

Gradle 示例大全
MIT License
209 stars 61 forks source link

Gradle多模块工程,A工程(Springboot)使用compile project依赖(B)工程,在Idea中正常运行,打包成jar提示找不到符号 #2

Closed youzhigithub closed 5 years ago

youzhigithub commented 6 years ago

使用Gradle多模块开发Spring cloud项目,A工程是个Springboot项目(eureka-server),B工程是个通用工具类的工程(core),A工程依赖B工程(在根项目的build.gradle中配置) image,同时在项目的settings文件中配置了依赖 image ,在idea中运行正常,当将A工程打包成jar运行时提示找不到符号(A工程中使用B工程代码的地方) image。 以下为配置文件的内容: 根项目的settings.gradle: rootProject.name = 'springcloud' include 'service-feign' include 'service-hi' include 'eureka-server' include 'service-zuul' include 'core'

根项目的build.gradle: buildscript { ext{ springBootVersion = '2.0.3.RELEASE' springCloudVersion = 'Finchley.RELEASE' } repositories { maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } mavenCentral() jcenter() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } allprojects { group 'com.su.sc' version '1.0.0'

apply plugin: 'org.springframework.boot'
apply plugin: 'idea'
apply plugin: 'java'

} subprojects{ apply plugin: 'io.spring.dependency-management'

sourceCompatibility = 1.8

repositories {
    maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
    mavenCentral()
    jcenter()
}

[compileJava,compileTestJava,javadoc]*.options*.encoding = 'UTF-8'

dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    compile('javax.servlet:javax.servlet-api:3.1.0')
    compile group: 'com.alibaba', name: 'fastjson', version: '1.2.47'

    compile(project(':core'))
    testCompile "org.springframework.boot:spring-boot-starter-test"
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

}

A项目的build.gradle(eureka-server) dependencies { compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client') compile('org.springframework.boot:spring-boot-starter-web') } B项目的build.gradle(core)

dependencies {

} configurations { all*.exclude module: 'core' }

打包方式为: 1、idea中选择任务 image 2、到A项目跟目录使用命令行:gradle build打包

pkaq commented 6 years ago

@youzhigithub B项目不要all exclude

youzhigithub commented 6 years ago

@pkaq 没有效果,依然报错。为了防止缓存,我重新起了一个项目。 A项目的配置: image B项目的配置: image

pkaq commented 6 years ago

a依赖b 但b要把自身排除掉 而不是全局排除

youzhigithub commented 6 years ago

@pkaq 我现在不是在打包的时候找不到B项目的代码吗? 还需要把B项目排除? common是现在的B项目,我这样配置后去打包依然报错呀,配置不对嘛 image

pkaq commented 6 years ago

其它可以依赖core 但core不要依赖core 循环依赖了 直接上可重现链接吧

youzhigithub commented 6 years ago

@pkaq https://github.com/youzhigithub/springcloud-demo 老哥这是demo地址,尝试打包service-hi的时候失败

pkaq commented 6 years ago

刚好我这有个sc的示例 参考一下 https://github.com/pkaq/springcloud7

youzhigithub commented 6 years ago

这个示例没有出现项目依赖..

shirayner commented 5 years ago

这个示例没有出现项目依赖..

老哥,我也出现了这个问题,请问您解决了吗?

iSayCheese commented 5 years ago

这个示例没有出现项目依赖..

请问老哥解决这个问题了么?

shirayner commented 5 years ago

今天再问一遍,老哥解决了吗

TomorJM commented 5 years ago

同问hh

pkaq commented 5 years ago

各种结构的多模块项目示例 https://github.com/GradleCN/GradleSide/tree/master/09-multi-project