-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
124 lines (104 loc) · 4.52 KB
/
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
buildscript {
ext { springBootVersion = '2.1.1.RELEASE' }
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "com.bmuschko:gradle-docker-plugin:4.2.0"
classpath "org.yaml:snakeyaml:1.23" // https://bitbucket.org/asomov/snakeyaml/wiki/Documentation
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.bmuschko.docker-spring-boot-application'
ext {
versionBase = '0.1.2'
springCloudVersion = 'Greenwich.RC1'
springProfilesActive = System.env.SPRING_PROFILES_ACTIVE == null ? ["default"]: System.env.SPRING_PROFILES_ACTIVE.split(',')
dockerRegistryUrl = 'https://index.docker.io/v1/'
dockerRegistryUser = 'dhoffi'
dockerTag = project.ext.dockerRegistryUser + (project.ext.dockerRegistryUser == "" ? "" : "/") + project.name +':' + project.ext.versionBase
dockerNetwork = 'mynetwork'
}
// after ext { }
apply from: "buildSpringConfig.gradle"
apply from: "buildVscode.gradle"
group = 'com.example'
version = project.ext.versionBase+'.SNAPSHOT'
//sourceCompatibility = 1.8
project.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
jcenter()
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" // for @ConfigurationProperties, make sure compileJava.dependsOn(processResources)
implementation 'org.springframework.cloud:spring-cloud-stream-binder-rabbit'
implementation 'org.springframework.amqp:spring-rabbit'
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('org.springframework.cloud:spring-cloud-stream-test-support') // messaging test support for spring-cloud-stream
testImplementation('org.springframework.security:spring-security-test')
}
springBoot {
mainClassName = "com.example.demo.DemoApplication"
}
docker {
springBootApplication {
//baseImage = 'openjdk:8-alpine'
baseImage = 'openjdk:11-jre-slim'
ports = ["${project.ext.getSpringAppconfig('server.port')}"]
tag = project.ext.dockerTag
registryCredentials {
url = project.ext.dockerRegistryUrl
username = project.ext.dockerRegistryUser
password = System.env.DOCKERHUB_PASS
}
}
}
task checkDockerhubPass(group:project.group, description:"check if DOCKERHUB_PASS is set in environment") {
doLast {
if ((System.env.DOCKERHUB_PASS == null) || (System.env.DOCKERHUB_PASS == "")) {
throw new GradleException('for accessing hub.docker.com you need to set system env variable DOCKERHUB_PASS')
}
}
}
dockerPushImage.dependsOn(checkDockerhubPass)
task printDockerRunCmds(group:project.group, description:"print docker run commands to console") {
doLast {
def dockerRunCmdsString = """
docker network create ${project.ext.dockerNetwork}
# RabbitMQ
docker run -d -p 5672:5672 -p 15672:15672 --network ${project.ext.dockerNetwork} --hostname my-rabbit --name some-rabbit rabbitmq:3.7.8-management-alpine
# ${project.name}
docker run -d -p 8081:${getSpringAppconfig('server.port')} --network ${project.ext.dockerNetwork} --name ${project.name} ${project.ext.dockerTag}
"""
println dockerRunCmdsString
}
}
dependencyManagement {
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
bootJar { launchScript() } // make the fat.jar executable (e.g. for sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp)
bootRun { systemProperties = System.properties } // ensure Gradle passes command line arguments to the JVM
test {
ignoreFailures true
reports.html.enabled = false
testLogging {
// Make sure test results are shown in Gradle output.
events "passed", "skipped", "failed" //, "standardOut", "standardError"
// Make sure output from standard out or error is shown in Gradle output.
showStandardStreams = true
exceptionFormat = 'full'
}
}