创建项目

项目地址: github.com/dongkw/spring-demo

  1. 创建一个gradle项目

  1. 删掉多余的src目录

  1. 创建子模块

  1. 删掉子模块里多余内容

  2. 修改子模块里build.gradle文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    version = '0.0.1-SNAPSHOT'

    dependencies {
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
    }

    bootJar {
    mainClassName = 'xyz.jecy.eureka.EurekaApplication'
    }

  3. 修改父级项目build.gradle文件

没有什么多余的引用,几乎都是必须的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

buildscript {
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
maven { url "https://plugins.gradle.org/m2/" }
}

}
plugins {
id "base"
id "io.spring.dependency-management" version "1.0.8.RELEASE"
id "org.springframework.boot" version "2.1.9.RELEASE"

}

group = 'xyz.jecy'
version = '0.0.1-SNAPSHOT'
allprojects {

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: "org.springframework.boot"
apply plugin: 'io.spring.dependency-management'
bootJar { enabled = false }

jar {
enabled = true
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Greenwich.SR3"
}
}

repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
maven { url "https://plugins.gradle.org/m2/" }
}


}

subprojects {

sourceCompatibility = 9
targetCompatibility = 9
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-Werror"
}
configurations {
providedRuntime

}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

}
  1. 执行 gradle clean build 命令
1
2
3
> Task :eureka:compileTestJava FAILED
/Users/xinzhilimacpro/mytestwork/spring-demo/eureka/src/test/java/xyz/jecy/eureka/EurekaApplicationTests.java:3: 错误: 程序包org.junit.jupiter.api不存在

失败了 但是因为eureka 不需要test,而且也没有引对应test的包 删掉

  1. 继续 gradle clean build
1
2
BUILD SUCCESSFUL in 2s
6 actionable tasks: 6 executed