聚合工程的最外层gradle配置 build.gradle
apply plugin: 'java'
buildscript {
ext {
// 定义变量
springBootVersion = '2.1.5.RELEASE'
springCloudVersion = 'Greenwich.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
repositories {
mavenCentral()
}
allprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencyManagement {
imports {
// 解决cloud零散jar的版本问题
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
// 统一移除jar
// configurations {
// all*.exclude module: 'spring-boot-starter-logging'
// }
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
// task wrapper(type: Wrapper) {
// gradleVersion = '6.4'
// distributionUrl = 'https://services.gradle.org/distributions/gradle-6.4-all.zip'
// }
repositories {
mavenLocal()
mavenCentral()
maven { setUrl("http://repo.maven.apache.org/maven2") }
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-test')
compile('org.springframework.boot:spring-boot-starter-aop')
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
}
}
settings.gradle
rootProject.name = 'zhy-web'
include(':zhy-eureka')
include(':zhy-user')
自动生成模块需要配置idea
zhy-eureka的配置
build.gradle
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
}
EurekaApplication
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
* @author zhy
* @date 2020/5/25 15:24
*/
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}
application.yml
server:
port: 6868
spring:
application:
name: eureka
eureka:
client:
register-with-eureka: false
fetch-registry: false
service-url:
# 浏览器打开: http://localhost:6868/
defaultZone: http://127.0.0.1:${server.port}/eureka/
zhy-user中的配置
build.gradle
apply plugin: 'war'
apply plugin: 'maven'
apply plugin: 'java'
group = 'com.zhy'
version = '1.0'
description = """"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('se.transmode.gradle:gradle-docker:1.2')
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.5.RELEASE"
}
}
apply plugin: "org.springframework.boot"
jar {
manifestContentCharset 'utf-8'
metadataCharset 'utf-8'
manifest {
attributes "Main-Class": "com.alibaba.user.Application"
}
from {
configurations.compile.collect { zipTree(it) }
}
}
repositories {
mavenLocal()
flatDir{ dirs 'libs'}
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}
maven { url "https://repo.maven.apache.org/maven2" }
}
dependencies {
compile project(':medical-viewer-db')
compile project(':medical-viewer-shiro')
compile group: 'org.springframework.data', name: 'spring-data-commons', version: '2.1.5.RELEASE'
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
}
application.java中加入注解
@EnableEurekaClient
application.yml
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:6868/eureka/
instance:
prefer-ip-address: true
zhy-user中的配置
build.gradle
// compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
compile group: 'com.alibaba.cloud', name: 'spring-cloud-starter-alibaba-nacos-discovery', version: '2.1.0.RELEASE'
application.properties或application.yml
#eureka.client.service-url.defaultZone=http://127.0.0.1:6868/eureka/
#eureka.instance.prefer-ip-address=true
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
spring.cloud.nacos.discovery.namespace=public
spring.application.name=user
spring:
application:
name: user
cloud:
nacos:
discovery:
namespace: public
server-addr: 127.0.0.1:8848
application.java中加入注解
@EnableDiscoveryClient