为了使用Vault为Spring Cloud Config server和(Java和非Java)客户端整合一个示例项目,我决定采用多模块Gradle构建的方式。因为我已经有了两个正在工作的Java项目(服务器和客户端),我想我可以将公共配置拉到父构建中。gradle
并有条件地应用Java子项目的配置。我从服务器子项目开始,遇到了一个我一直无法解决的问题。
构建。父模块的gradle
如下所示:
plugins {
id 'org.springframework.boot' version '2.3.0.RELEASE' apply false
id 'io.spring.dependency-management' version '1.0.9.RELEASE' apply false
id 'idea'
}
ext {
set('springCloudVersion', "Hoxton.SR4")
}
allprojects {
repositories {
mavenCentral()
}
version = '0.0.1-SNAPSHOT'
}
subprojects {
// We'll need dependencies for Docker and Docker compose
afterEvaluate { project ->
if (project.usesSpringBoot) {
println("Configuring ${springCloudVersion}")
configure(project) {
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
group = 'com.daecabhir'
sourceCompatibility = '11'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
}
}
}
}
以及构建。gradle
对于云配置服务器
子项目,如下所示:
ext {
usesSpringBoot = true
}
不幸的是,正在尝试/gradlew build
给我留下了一个错误,它无法从Spring Cloud Config中找到类:
/home/gwright/projects/cloud-config-vault-example/cloud-config-server/src/main/java/com/daecabhir/cloudconfigserver/CloudConfigServerApplication.java:5: error: package org.springframework.cloud.config.server does not exist
import org.springframework.cloud.config.server.EnableConfigServer;
^
/home/gwright/projects/cloud-config-vault-example/cloud-config-server/src/main/java/com/daecabhir/cloudconfigserver/CloudConfigServerApplication.java:7: error: cannot find symbol
@EnableConfigServer
^
symbol: class EnableConfigServer
2 errors
当我检查依赖项时,我会在编译时得到以下结果:
compileClasspath - Compile classpath for source set 'main'.
+--- org.springframework.boot:spring-boot-starter-actuator -> 2.3.0.RELEASE
| +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE
| | +--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (c)
| | +--- io.micrometer:micrometer-core:1.5.1 (c)
| | +--- org.springframework:spring-web:5.2.6.RELEASE (c)
| | +--- org.springframework:spring-webmvc:5.2.6.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-actuator-autoconfigure:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter-actuator:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter-json:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter-tomcat:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter-web:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-autoconfigure:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter-logging:2.3.0.RELEASE (c)
| | +--- jakarta.annotation:jakarta.annotation-api:1.3.5 (c)
| | +--- org.springframework:spring-core:5.2.6.RELEASE (c)
| | +--- org.yaml:snakeyaml:1.26 (c)
| | +--- org.springframework.boot:spring-boot-actuator:2.3.0.RELEASE (c)
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.0 (c)
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.0 (c)
| | +--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.0 (c)
| | +--- org.apache.tomcat.embed:tomcat-embed-core:9.0.35 (c)
| | +--- org.glassfish:jakarta.el:3.0.3 (c)
| | +--- org.apache.tomcat.embed:tomcat-embed-websocket:9.0.35 (c)
| | +--- org.springframework:spring-beans:5.2.6.RELEASE (c)
| | +--- org.springframework:spring-aop:5.2.6.RELEASE (c)
| | +--- org.springframework:spring-context:5.2.6.RELEASE (c)
| | +--- org.springframework:spring-expression:5.2.6.RELEASE (c)
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.11.0 (c)
| | +--- com.fasterxml.jackson.core:jackson-core:2.11.0 (c)
| | +--- ch.qos.logback:logback-classic:1.2.3 (c)
| | +--- org.apache.logging.log4j:log4j-to-slf4j:2.13.2 (c)
| | +--- org.slf4j:jul-to-slf4j:1.7.30 (c)
| | +--- org.springframework:spring-jcl:5.2.6.RELEASE (c)
| | +--- org.springframework.security:spring-security-crypto:5.3.2.RELEASE (c)
| | +--- ch.qos.logback:logback-core:1.2.3 (c)
| | +--- org.slf4j:slf4j-api:1.7.30 (c)
| | \--- org.apache.logging.log4j:log4j-api:2.13.2 (c)
| +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE
| | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | +--- org.springframework.boot:spring-boot:2.3.0.RELEASE
| | | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | | +--- org.springframework:spring-core -> 5.2.6.RELEASE
| | | | \--- org.springframework:spring-jcl:5.2.6.RELEASE
| | | \--- org.springframework:spring-context -> 5.2.6.RELEASE
| | | +--- org.springframework:spring-aop:5.2.6.RELEASE
| | | | +--- org.springframework:spring-beans:5.2.6.RELEASE
| | | | | \--- org.springframework:spring-core:5.2.6.RELEASE (*)
| | | | \--- org.springframework:spring-core:5.2.6.RELEASE (*)
| | | +--- org.springframework:spring-beans:5.2.6.RELEASE (*)
| | | +--- org.springframework:spring-core:5.2.6.RELEASE (*)
| | | \--- org.springframework:spring-expression:5.2.6.RELEASE
| | | \--- org.springframework:spring-core:5.2.6.RELEASE (*)
| | +--- org.springframework.boot:spring-boot-autoconfigure:2.3.0.RELEASE
| | | +--- org.springframework.boot:spring-boot:2.3.0.RELEASE (*)
| | | \--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | +--- org.springframework.boot:spring-boot-starter-logging:2.3.0.RELEASE
| | | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | | +--- ch.qos.logback:logback-classic -> 1.2.3
| | | | +--- ch.qos.logback:logback-core:1.2.3
| | | | \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
| | | +--- org.apache.logging.log4j:log4j-to-slf4j -> 2.13.2
| | | | +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
| | | | \--- org.apache.logging.log4j:log4j-api:2.13.2
| | | \--- org.slf4j:jul-to-slf4j -> 1.7.30
| | | \--- org.slf4j:slf4j-api:1.7.30
| | +--- jakarta.annotation:jakarta.annotation-api -> 1.3.5
| | +--- org.springframework:spring-core -> 5.2.6.RELEASE (*)
| | \--- org.yaml:snakeyaml -> 1.26
| +--- org.springframework.boot:spring-boot-actuator-autoconfigure:2.3.0.RELEASE
| | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | \--- org.springframework.boot:spring-boot-actuator:2.3.0.RELEASE
| | \--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| \--- io.micrometer:micrometer-core -> 1.5.1
| \--- org.hdrhistogram:HdrHistogram:2.1.12
+--- org.springframework.boot:spring-boot-starter-web -> 2.3.0.RELEASE
| +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE (*)
| +--- org.springframework.boot:spring-boot-starter-json:2.3.0.RELEASE
| | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE (*)
| | +--- org.springframework:spring-web -> 5.2.6.RELEASE
| | | +--- org.springframework:spring-beans:5.2.6.RELEASE (*)
| | | \--- org.springframework:spring-core:5.2.6.RELEASE (*)
| | +--- com.fasterxml.jackson.core:jackson-databind -> 2.11.0
| | | +--- com.fasterxml.jackson.core:jackson-annotations:2.11.0
| | | \--- com.fasterxml.jackson.core:jackson-core:2.11.0
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8 -> 2.11.0
| | | +--- com.fasterxml.jackson.core:jackson-core:2.11.0
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (*)
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310 -> 2.11.0
| | | +--- com.fasterxml.jackson.core:jackson-annotations:2.11.0
| | | +--- com.fasterxml.jackson.core:jackson-core:2.11.0
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (*)
| | \--- com.fasterxml.jackson.module:jackson-module-parameter-names -> 2.11.0
| | +--- com.fasterxml.jackson.core:jackson-core:2.11.0
| | \--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (*)
| +--- org.springframework.boot:spring-boot-starter-tomcat:2.3.0.RELEASE
| | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | +--- jakarta.annotation:jakarta.annotation-api -> 1.3.5
| | +--- org.apache.tomcat.embed:tomcat-embed-core -> 9.0.35
| | +--- org.glassfish:jakarta.el -> 3.0.3
| | \--- org.apache.tomcat.embed:tomcat-embed-websocket -> 9.0.35
| | \--- org.apache.tomcat.embed:tomcat-embed-core:9.0.35
| +--- org.springframework:spring-web -> 5.2.6.RELEASE (*)
| \--- org.springframework:spring-webmvc -> 5.2.6.RELEASE
| +--- org.springframework:spring-aop:5.2.6.RELEASE (*)
| +--- org.springframework:spring-beans:5.2.6.RELEASE (*)
| +--- org.springframework:spring-context:5.2.6.RELEASE (*)
| +--- org.springframework:spring-core:5.2.6.RELEASE (*)
| +--- org.springframework:spring-expression:5.2.6.RELEASE (*)
| \--- org.springframework:spring-web:5.2.6.RELEASE (*)
\--- org.springframework.cloud:spring-cloud-starter-config -> 2.2.2.RELEASE
+--- org.springframework.cloud:spring-cloud-starter:2.2.2.RELEASE
| +--- org.springframework.boot:spring-boot-starter:2.2.5.RELEASE -> 2.3.0.RELEASE (*)
| +--- org.springframework.cloud:spring-cloud-context:2.2.2.RELEASE
| | \--- org.springframework.security:spring-security-crypto:5.2.2.RELEASE -> 5.3.2.RELEASE
| +--- org.springframework.cloud:spring-cloud-commons:2.2.2.RELEASE
| | \--- org.springframework.security:spring-security-crypto:5.2.2.RELEASE -> 5.3.2.RELEASE
| \--- org.springframework.security:spring-security-rsa:1.0.9.RELEASE
| \--- org.bouncycastle:bcpkix-jdk15on:1.64
| \--- org.bouncycastle:bcprov-jdk15on:1.64
+--- org.springframework.cloud:spring-cloud-config-client:2.2.2.RELEASE
| +--- org.springframework.boot:spring-boot-autoconfigure:2.2.5.RELEASE -> 2.3.0.RELEASE (*)
| +--- org.springframework.cloud:spring-cloud-commons:2.2.2.RELEASE (*)
| +--- org.springframework.cloud:spring-cloud-context:2.2.2.RELEASE (*)
| +--- org.springframework:spring-web:5.2.4.RELEASE -> 5.2.6.RELEASE (*)
| +--- com.fasterxml.jackson.core:jackson-annotations:2.10.2 -> 2.11.0
| \--- com.fasterxml.jackson.core:jackson-databind:2.10.2 -> 2.11.0 (*)
\--- com.fasterxml.jackson.core:jackson-databind:2.10.2 -> 2.11.0 (*)
从表面上看,这似乎是合理的,但事实并非如此。Gradle似乎尊重依赖关系,但依赖关系管理并没有完全解决这些问题。当我回到使用以下父构建在
:云配置服务器
子项目中完全指定配置时。格雷德尔
plugins {
id 'org.springframework.boot' version '2.3.0.RELEASE' apply false
id 'io.spring.dependency-management' version '1.0.9.RELEASE' apply false
id 'idea'
}
ext {
set('springCloudVersion', "Hoxton.SR4")
}
allprojects {
repositories {
mavenCentral()
}
version = '0.0.1-SNAPSHOT'
}
以及一个子项目build。gradle
of:
plugins {
id 'org.springframework.boot'
id 'io.spring.dependency-management'
id 'java'
}
group = 'com.daecabhir'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-config-server'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
构建工作正常,依赖关系得到了更全面的“解决”(尤其是spring cloud config服务器依赖关系):
compileClasspath - Compile classpath for source set 'main'.
+--- org.springframework.boot:spring-boot-starter-web -> 2.3.0.RELEASE
| +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE
| | +--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.11.0 (c)
| | +--- org.springframework:spring-web:5.2.6.RELEASE (c)
| | +--- org.springframework:spring-webmvc:5.2.6.RELEASE (c)
| | +--- org.springframework.security:spring-security-crypto:5.3.2.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter-actuator:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter-json:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter-tomcat:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter-validation:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter-web:2.3.0.RELEASE (c)
| | +--- org.yaml:snakeyaml:1.26 (c)
| | +--- org.springframework.boot:spring-boot:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-autoconfigure:2.3.0.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-starter-logging:2.3.0.RELEASE (c)
| | +--- jakarta.annotation:jakarta.annotation-api:1.3.5 (c)
| | +--- org.springframework:spring-core:5.2.6.RELEASE (c)
| | +--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (c)
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.0 (c)
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.0 (c)
| | +--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.0 (c)
| | +--- org.apache.tomcat.embed:tomcat-embed-core:9.0.35 (c)
| | +--- org.glassfish:jakarta.el:3.0.3 (c)
| | +--- org.apache.tomcat.embed:tomcat-embed-websocket:9.0.35 (c)
| | +--- org.springframework:spring-beans:5.2.6.RELEASE (c)
| | +--- org.springframework:spring-aop:5.2.6.RELEASE (c)
| | +--- org.springframework:spring-context:5.2.6.RELEASE (c)
| | +--- org.springframework:spring-expression:5.2.6.RELEASE (c)
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.11.0 (c)
| | +--- org.springframework.boot:spring-boot-actuator-autoconfigure:2.3.0.RELEASE (c)
| | +--- io.micrometer:micrometer-core:1.5.1 (c)
| | +--- org.hibernate.validator:hibernate-validator:6.1.5.Final (c)
| | +--- org.slf4j:slf4j-api:1.7.30 (c)
| | +--- org.apache.httpcomponents:httpclient:4.5.12 (c)
| | +--- org.apache.httpcomponents:httpcore:4.4.13 (c)
| | +--- com.fasterxml.jackson.core:jackson-core:2.11.0 (c)
| | +--- ch.qos.logback:logback-classic:1.2.3 (c)
| | +--- org.apache.logging.log4j:log4j-to-slf4j:2.13.2 (c)
| | +--- org.slf4j:jul-to-slf4j:1.7.30 (c)
| | +--- org.springframework:spring-jcl:5.2.6.RELEASE (c)
| | +--- org.springframework.boot:spring-boot-actuator:2.3.0.RELEASE (c)
| | +--- jakarta.validation:jakarta.validation-api:2.0.2 (c)
| | +--- org.jboss.logging:jboss-logging:3.4.1.Final (c)
| | +--- com.fasterxml:classmate:1.5.1 (c)
| | +--- commons-codec:commons-codec:1.14 (c)
| | +--- ch.qos.logback:logback-core:1.2.3 (c)
| | \--- org.apache.logging.log4j:log4j-api:2.13.2 (c)
| +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE
| | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | +--- org.springframework.boot:spring-boot:2.3.0.RELEASE
| | | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | | +--- org.springframework:spring-core -> 5.2.6.RELEASE
| | | | \--- org.springframework:spring-jcl:5.2.6.RELEASE
| | | \--- org.springframework:spring-context -> 5.2.6.RELEASE
| | | +--- org.springframework:spring-aop:5.2.6.RELEASE
| | | | +--- org.springframework:spring-beans:5.2.6.RELEASE
| | | | | \--- org.springframework:spring-core:5.2.6.RELEASE (*)
| | | | \--- org.springframework:spring-core:5.2.6.RELEASE (*)
| | | +--- org.springframework:spring-beans:5.2.6.RELEASE (*)
| | | +--- org.springframework:spring-core:5.2.6.RELEASE (*)
| | | \--- org.springframework:spring-expression:5.2.6.RELEASE
| | | \--- org.springframework:spring-core:5.2.6.RELEASE (*)
| | +--- org.springframework.boot:spring-boot-autoconfigure:2.3.0.RELEASE
| | | +--- org.springframework.boot:spring-boot:2.3.0.RELEASE (*)
| | | \--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | +--- org.springframework.boot:spring-boot-starter-logging:2.3.0.RELEASE
| | | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | | +--- ch.qos.logback:logback-classic -> 1.2.3
| | | | +--- ch.qos.logback:logback-core:1.2.3
| | | | \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
| | | +--- org.apache.logging.log4j:log4j-to-slf4j -> 2.13.2
| | | | +--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
| | | | \--- org.apache.logging.log4j:log4j-api:2.13.2
| | | \--- org.slf4j:jul-to-slf4j -> 1.7.30
| | | \--- org.slf4j:slf4j-api:1.7.30
| | +--- jakarta.annotation:jakarta.annotation-api -> 1.3.5
| | +--- org.springframework:spring-core -> 5.2.6.RELEASE (*)
| | \--- org.yaml:snakeyaml -> 1.26
| +--- org.springframework.boot:spring-boot-starter-json:2.3.0.RELEASE
| | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE (*)
| | +--- org.springframework:spring-web -> 5.2.6.RELEASE
| | | +--- org.springframework:spring-beans:5.2.6.RELEASE (*)
| | | \--- org.springframework:spring-core:5.2.6.RELEASE (*)
| | +--- com.fasterxml.jackson.core:jackson-databind -> 2.11.0
| | | +--- com.fasterxml.jackson.core:jackson-annotations:2.11.0
| | | \--- com.fasterxml.jackson.core:jackson-core:2.11.0
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jdk8 -> 2.11.0
| | | +--- com.fasterxml.jackson.core:jackson-core:2.11.0
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (*)
| | +--- com.fasterxml.jackson.datatype:jackson-datatype-jsr310 -> 2.11.0
| | | +--- com.fasterxml.jackson.core:jackson-annotations:2.11.0
| | | +--- com.fasterxml.jackson.core:jackson-core:2.11.0
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (*)
| | \--- com.fasterxml.jackson.module:jackson-module-parameter-names -> 2.11.0
| | +--- com.fasterxml.jackson.core:jackson-core:2.11.0
| | \--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (*)
| +--- org.springframework.boot:spring-boot-starter-tomcat:2.3.0.RELEASE
| | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | +--- jakarta.annotation:jakarta.annotation-api -> 1.3.5
| | +--- org.apache.tomcat.embed:tomcat-embed-core -> 9.0.35
| | +--- org.glassfish:jakarta.el -> 3.0.3
| | \--- org.apache.tomcat.embed:tomcat-embed-websocket -> 9.0.35
| | \--- org.apache.tomcat.embed:tomcat-embed-core:9.0.35
| +--- org.springframework:spring-web -> 5.2.6.RELEASE (*)
| \--- org.springframework:spring-webmvc -> 5.2.6.RELEASE
| +--- org.springframework:spring-aop:5.2.6.RELEASE (*)
| +--- org.springframework:spring-beans:5.2.6.RELEASE (*)
| +--- org.springframework:spring-context:5.2.6.RELEASE (*)
| +--- org.springframework:spring-core:5.2.6.RELEASE (*)
| +--- org.springframework:spring-expression:5.2.6.RELEASE (*)
| \--- org.springframework:spring-web:5.2.6.RELEASE (*)
\--- org.springframework.cloud:spring-cloud-config-server -> 2.2.2.RELEASE
+--- org.springframework.cloud:spring-cloud-config-client:2.2.2.RELEASE
| +--- org.springframework.boot:spring-boot-autoconfigure:2.2.5.RELEASE -> 2.3.0.RELEASE (*)
| +--- org.springframework.cloud:spring-cloud-commons:2.2.2.RELEASE
| | \--- org.springframework.security:spring-security-crypto:5.2.2.RELEASE -> 5.3.2.RELEASE
| +--- org.springframework.cloud:spring-cloud-context:2.2.2.RELEASE
| | \--- org.springframework.security:spring-security-crypto:5.2.2.RELEASE -> 5.3.2.RELEASE
| +--- org.springframework:spring-web:5.2.4.RELEASE -> 5.2.6.RELEASE (*)
| +--- com.fasterxml.jackson.core:jackson-annotations:2.10.2 -> 2.11.0
| \--- com.fasterxml.jackson.core:jackson-databind:2.10.2 -> 2.11.0 (*)
+--- org.springframework.boot:spring-boot-starter-actuator:2.2.5.RELEASE -> 2.3.0.RELEASE
| +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE (*)
| +--- org.springframework.boot:spring-boot-actuator-autoconfigure:2.3.0.RELEASE
| | +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| | \--- org.springframework.boot:spring-boot-actuator:2.3.0.RELEASE
| | \--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| \--- io.micrometer:micrometer-core -> 1.5.1
| \--- org.hdrhistogram:HdrHistogram:2.1.12
+--- org.springframework.boot:spring-boot-starter-web:2.2.5.RELEASE -> 2.3.0.RELEASE (*)
+--- org.springframework.boot:spring-boot-starter-validation:2.2.5.RELEASE -> 2.3.0.RELEASE
| +--- org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE (*)
| +--- org.springframework.boot:spring-boot-starter:2.3.0.RELEASE (*)
| +--- org.glassfish:jakarta.el -> 3.0.3
| \--- org.hibernate.validator:hibernate-validator -> 6.1.5.Final
| +--- jakarta.validation:jakarta.validation-api:2.0.2
| +--- org.jboss.logging:jboss-logging:3.3.2.Final -> 3.4.1.Final
| \--- com.fasterxml:classmate:1.3.4 -> 1.5.1
+--- org.springframework.security:spring-security-crypto:5.2.2.RELEASE -> 5.3.2.RELEASE
+--- org.springframework.security:spring-security-rsa:1.0.9.RELEASE
| \--- org.bouncycastle:bcpkix-jdk15on:1.64
| \--- org.bouncycastle:bcprov-jdk15on:1.64
+--- org.eclipse.jgit:org.eclipse.jgit:5.1.3.201810200350-r
| +--- com.jcraft:jsch:0.1.54
| +--- com.jcraft:jzlib:1.1.1
| +--- com.googlecode.javaewah:JavaEWAH:1.1.6
| \--- org.slf4j:slf4j-api:1.7.2 -> 1.7.30
+--- org.eclipse.jgit:org.eclipse.jgit.http.apache:5.1.3.201810200350-r
| +--- org.eclipse.jgit:org.eclipse.jgit:5.1.3.201810200350-r (*)
| +--- org.apache.httpcomponents:httpclient:4.5.5 -> 4.5.12
| | +--- org.apache.httpcomponents:httpcore:4.4.13
| | \--- commons-codec:commons-codec:1.11 -> 1.14
| \--- org.apache.httpcomponents:httpcore:4.4.9 -> 4.4.13
+--- org.yaml:snakeyaml:1.25 -> 1.26
\--- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.10.2 -> 2.11.0
+--- com.fasterxml.jackson.core:jackson-databind:2.11.0 (*)
+--- org.yaml:snakeyaml:1.26
\--- com.fasterxml.jackson.core:jackson-core:2.11.0
所以我的问题是,为了能够基于属性选择性地指定父项目中的配置,以便完全解决依赖关系,我需要做什么?我是如何指定导致它无法完全解决依赖关系的配置的?
FWIW,项目的完整代码可以在这里找到:
我已经为你的回购做了公关:https://github.com/daecabhir/cloud-config-vault-example/pull/3
您可以定义一个基于Spring Boot的项目列表,然后应用您已经完成的默认值,而不是使用属性来控制项目是否是Spring Boot项目(对我来说不起作用)。
plugins {
id 'org.springframework.boot' version '2.3.0.RELEASE' apply false
id 'io.spring.dependency-management' version '1.0.9.RELEASE' apply false
id 'idea'
}
ext {
set('springCloudVersion', "Hoxton.SR4")
}
allprojects {
repositories {
mavenCentral()
}
version = '0.0.1-SNAPSHOT'
}
// List of Spring Boot based projects
def springBootProjects = [
project(":cloud-config-server"),
project(":cloud-config-client")
]
一旦你有了你的列表,然后简单地迭代它们,对它们应用基于配置:
springBootProjects.each { springBootProject ->
configure(springBootProject) {
println("Configuring $name as a Spring Boot project")
apply {
plugin("org.springframework.boot")
plugin("io.spring.dependency-management")
plugin("java")
}
group = "com.daecabhir"
sourceCompatibility = "11"
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks {
test {
useJUnitPlatform()
}
}
}
}
您将spring cloud starter config
作为服务器应用程序的导入,但这是不正确的,因为spring cloud starter config
模块引入了spring cloud config client
,这不是配置服务器所需的,因为它会导致导入问题。
因此,与其将依赖项定义为基础依赖项,不如将其移动到项目本身:
云配置服务器build.gradle
dependencies {
implementation "org.springframework.cloud:spring-cloud-config-server"
}
云配置客户端build.gradle
dependencies {
implementation "org.springframework.cloud:spring-cloud-starter-config"
}
通过这些更改,结果输出为:
$ ./gradlew assemble
> Configure project :
Configuring cloud-config-server as a Spring Boot project
Configuring cloud-config-client as a Spring Boot project
BUILD SUCCESSFUL in 2s
6 actionable tasks: 6 up-to-date
我按照以下指南将项目分为模块/子项目: https://docs.gradle.org/current/userguide/multi_project_builds.html 在主脚本中,我应用子项目的配置: 如果我从根build目录运行子项目build,这会很好: (成功构建
Ivy可以解决依赖关系的依赖关系,留档说可以使用模块配置来告诉Ivy配置取决于依赖关系的给定配置。 我想在一个项目中使用htmlunit,在它的sourceforge页面依赖信息中我找到了依赖设置,我把maven规范翻译成ivy: 我写了一个测试,编译了它,当尝试运行它时,我有一个ClassNotFoundException,我再次返回sourceforge,查找关于htmlunit依赖关系的信息
我如何在一个Android Gradle项目中设置模块的依赖关系,在这个项目中,模块之间相互依赖,这样我就可以一次部署所有模块的新快照或发布版本的构建? 该项目的结构如下: 项目配置文件如下,仅显示相关部分(根据我的判断): 设置。分级: lib-help/gradle.properties: lib-help/build.gradle: 当我运行时,所有内容都编译得很好,并且上载文件被推送到正确
我有一个由两个模块组成的项目。其中一个被认为是主要的。所以第二个取决于第一个。我还应该为模块生成javadoc jar文件。输出应为四。jar文件:2个模块jar文件和两个javadoc jar文件。 在本地,要生成两个jar文件,我应该重复这些步骤几次(我不知道为什么): > 构建第一个并安装到本地maven存储库。 然后我可以建造第二个。 如果不安装第一个模块,我就无法实现打包阶段,因为当我测
基于文档(4.7.6 -了解特定的依赖关系),我们可以通过指定配置本身来了解特定的配置。在示例中,他们将配置< code>compile用作不推荐使用的配置。我试图重现相同的命令,将< code>build.gradle中的< code>compile配置替换为< code>implementation配置(正如我所得到的,我们不应该再使用< code>compile)。但是当我跑的时候: Gra
本文向大家介绍android-gradle 如何在build.gradle中配置构建类型,包括了android-gradle 如何在build.gradle中配置构建类型的使用技巧和注意事项,需要的朋友参考一下 示例 您可以build.gradle在android {}块内的模块级文件中创建和配置构建类型。