Skip to content

Commit f6ac1db

Browse files
authored
Update gradle build configuration to support multi-project build (#42)
* Update dependencies and gradle wrapper * Initial restructure for multiproject gradle build * Update Travis-CI to use JDK11 but also build against early access * Update to using Java 11 options in Dockerfile * Stop logging of query string as it is unsafe, instead use spring actuator /actuator/httptrace endpoint * Run sonarqube in after_success phase in test stage
1 parent d7690b5 commit f6ac1db

22 files changed

+141
-145
lines changed

.travis.yml

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: java
22
jdk:
3-
- openjdk8
43
- openjdk11
4+
- openjdk-ea
55
env:
66
global:
77
# Following encrypted environment variables must be present for successful deployment
@@ -21,15 +21,14 @@ cache:
2121
directories:
2222
- "$HOME/.gradle/caches/"
2323
- "$HOME/.gradle/wrapper/"
24-
- "$HOME/.local"
25-
script:
26-
- ./gradlew check sonarqube
2724
jobs:
2825
include:
2926
- stage: test
27+
after_success:
28+
- ./gradlew sonarqube
3029
- stage: deploy to development
3130
if: env(DEV_ACCOUNT_ID) is present
32-
jdk: openjdk8
31+
jdk: openjdk11
3332
env:
3433
- CLUSTER_NAME=
3534
- SERVICE_NAME=
@@ -46,13 +45,14 @@ jobs:
4645
branch: master
4746
- stage: deploy to production
4847
if: env(PROD_ACCOUNT_ID) is present
49-
jdk: openjdk8
48+
jdk: openjdk11
5049
env:
5150
- CLUSTER_NAME=
5251
- SERVICE_NAME=
5352
- AWS_ACCESS_KEY_ID=$PROD_ACCESS_KEY_ID
5453
- AWS_SECRET_ACCESS_KEY=$PROD_SECRET_ACCESS_KEY
5554
- REPOSITORY_URI=$PROD_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$ECR_REPOSITORY_NAME
55+
script: skip
5656
before_deploy: deployment/scripts/common/push-docker-image.sh
5757
deploy:
5858
skip_cleanup: true
@@ -61,8 +61,7 @@ jobs:
6161
on:
6262
branch: master
6363
allow_failures:
64-
- jdk: openjdk10
65-
- jdk: openjdk11
64+
- jdk: openjdk-ea
6665
fast_finish: true
6766
notifications:
6867
slack:

README.md

+2-23
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,7 @@
66

77
## How tos
88

9-
### Build and Test
10-
For IDEs run one of the following commands before importing into your IDE.
11-
12-
#### IntelliJ
13-
```bash
14-
./gradlew idea
15-
```
16-
17-
#### Eclipse
18-
```bash
19-
./gradlew eclipse
20-
```
21-
22-
#### Build & Test
9+
### Build & Test
2310
```bash
2411
./gradlew clean assemble check
2512
```
@@ -37,22 +24,14 @@ docker run -p 8080:8080 -i -t -e JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,s
3724
### Enabling New Relic
3825
New relic can be enabled by providing the following `JAVA_OPTS` environment variable. Ensure to provide the correct `newrelic.environment` system property. To configure New Relic add/update the Application Environments section in `newrelic.yml`, more information can be found [here](https://docs.newrelic.com/docs/agents/java-agent/configuration/java-agent-configuration-config-file).
3926
```base
40-
docker run -p 8080:8080 -i -t -e JAVA_OPTS="-javaagent:newrelic/newrelic.jar -Dnewrelic.environment=${environment} -Dnewrelic.config.file=newrelic/newrelic.yml" spring-boot-java-base
27+
docker run -p 8080:8080 -i -t -e JAVA_OPTS="-javaagent:newrelic/newrelic.jar -Dnewrelic.environment=development -Dnewrelic.config.file=newrelic/newrelic.yml" spring-boot-java-base
4128
```
4229

4330
### How to: Build production equivalent container
4431
```bash
4532
./gradlew clean assemble check docker dockerTag -PTAG=$(git rev-parse --verify HEAD --short) -PREPOSITORY_URI=${DOCKER_REPO}${IMAGE_NAME}
4633
```
4734

48-
#### Recommended JAVA_OPTS
49-
It is strongly recommended that the following Java Options are set when running the service in production.
50-
51-
**-XX:MaxRAMFraction=n** should only be set to 1 for containers with only 1 processes running. Setting the value will set the heap to 100% of the memory in the container.
52-
```base
53-
JAVA_OPTS="-XX:MaxRAMFraction=2 -XX:+UseG1GC -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -javaagent:newrelic/newrelic.jar -Dnewrelic.environment=${environment} -Dnewrelic.config.file=newrelic/newrelic.yml -Djava.security.egd=file:/dev/./urandom"
54-
```
55-
5635
## For more tasks run
5736
```bash
5837
./gradlew tasks

build.gradle

+51-97
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,70 @@
11
plugins {
2-
id 'java'
3-
id 'jacoco'
4-
id 'checkstyle'
52
id 'eclipse'
63
id 'idea'
7-
id "com.github.spotbugs" version "1.6.6"
8-
id "org.springframework.boot" version "2.1.1.RELEASE"
9-
id "io.spring.dependency-management" version "1.0.6.RELEASE"
10-
id "com.palantir.docker" version "0.20.1"
11-
id "org.sonarqube" version "2.6.2"
12-
id "com.gorylenko.gradle-git-properties" version "1.5.2"
4+
id "org.sonarqube" version "2.7" apply false
5+
id "com.github.spotbugs" version "1.6.9" apply false
136
}
147

15-
16-
group = 'com.bnc'
17-
version = '0.0.1-SNAPSHOT'
18-
19-
sourceCompatibility = 1.8
20-
targetCompatibility = 1.8
21-
22-
compileJava.options.encoding = "UTF-8"
23-
24-
repositories {
25-
mavenCentral()
26-
maven { url "https://repo.spring.io/milestone" }
27-
}
28-
29-
spotbugs {
30-
toolVersion = '3.1.10'
31-
}
32-
33-
jacoco {
34-
toolVersion = "0.8.2"
35-
}
36-
37-
checkstyle {
38-
toolVersion '8.15'
39-
}
40-
41-
springBoot {
42-
buildInfo()
43-
}
44-
45-
tasks.withType(com.github.spotbugs.SpotBugsTask) {
46-
reports {
47-
xml.enabled = false
48-
html.enabled = true
8+
allprojects {
9+
apply plugin: 'java'
10+
apply plugin: 'jacoco'
11+
apply plugin: 'checkstyle'
12+
apply plugin: 'com.github.spotbugs'
13+
apply plugin: 'org.sonarqube'
14+
15+
group = 'com.bnc'
16+
version = '0.0.1-SNAPSHOT'
17+
sourceCompatibility = JavaVersion.VERSION_11
18+
targetCompatibility = JavaVersion.VERSION_11
19+
compileJava.options.encoding = "UTF-8"
20+
21+
repositories {
22+
mavenCentral()
23+
jcenter()
4924
}
50-
}
5125

52-
jacocoTestReport {
53-
reports {
54-
xml.enabled true
55-
html.enabled true
56-
csv.enabled false
26+
spotbugs {
27+
toolVersion = '3.1.12'
28+
tasks.withType(com.github.spotbugs.SpotBugsTask) {
29+
reports {
30+
xml.enabled = false
31+
html.enabled = true
32+
}
33+
}
5734
}
58-
}
5935

60-
sonarqube {
61-
properties {
62-
property "sonar.projectKey", "${project.name}"
63-
property "sonar.coverage.exclusions", "**/configuration/*"
64-
property "sonar.cpd.exclusions", "**/model/api/*,**/model/entity/*"
36+
jacoco {
37+
toolVersion = "0.8.3"
6538
}
66-
}
6739

68-
test {
69-
useJUnitPlatform()
70-
testLogging {
71-
events "passed", "skipped", "failed"
40+
checkstyle {
41+
toolVersion '8.19'
42+
tasks.withType(Checkstyle) {
43+
reports {
44+
xml.enabled false
45+
html.enabled true
46+
}
47+
}
7248
}
7349

74-
jacoco {
75-
excludes += [ '**/configuration/**' ]
50+
test {
51+
useJUnitPlatform()
52+
testLogging {
53+
events "passed", "skipped", "failed"
54+
}
7655
}
77-
finalizedBy jacocoTestReport
78-
}
79-
80-
if (!project.hasProperty("REPOSITORY_URI")) {
81-
ext.REPOSITORY_URI = jar.baseName
82-
}
8356

84-
if (!project.hasProperty("TAG")) {
85-
ext.TAG = jar.version
86-
}
87-
88-
docker {
89-
name project.hasProperty("REPOSITORY_URI") ? "${REPOSITORY_URI}" : "${project.name}"
90-
tags "${TAG}", 'latest'
91-
files bootJar.archivePath, "${project.projectDir.absolutePath}/config/newrelic/newrelic.yml"
92-
buildArgs(['JAR_FILE': "${bootJar.archiveName}"])
93-
}
94-
95-
dependencyManagement {
96-
imports {
97-
mavenBom "org.springframework.cloud:spring-cloud-sleuth:2.1.0.M2"
57+
dependencies {
58+
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.4.1'
59+
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.12.2'
60+
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.26.0'
61+
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '2.26.0'
62+
testRuntime group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.4.1'
9863
}
9964
}
10065

101-
dependencies {
102-
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
103-
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
104-
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth'
105-
implementation group: 'com.github.spotbugs', name: 'spotbugs-annotations', version: '3.1.10'
106-
implementation group: 'io.micrometer', name: 'micrometer-registry-new-relic', version: '1.1.1'
107-
runtime group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
108-
109-
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
110-
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.3.2'
111-
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.11.1'
112-
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
113-
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '2.23.4'
114-
testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.3.2'
115-
testRuntime group: 'com.h2database', name: 'h2', version: '1.4.197'
66+
sonarqube {
67+
properties {
68+
property "sonar.projectKey", "${rootProject.name}"
69+
}
11670
}

client/build.gradle

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
jar {
2+
baseName = rootProject.name + "-" + project.name
3+
}
4+
5+
sonarqube {
6+
properties {
7+
property "sonar.projectKey", "${rootProject.name}:${project.name}"
8+
}
9+
}

deployment/templates/service.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ Parameters:
9191
MemoryReservation:
9292
Description: The memory reservation for the task, this is the expected upper limit during normal operations.
9393
Type: Number
94-
Default: 768
94+
Default: 512
9595
AllowedValues: [16, 32, 64, 128, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096]
9696

9797
MemoryLimit:
9898
Description: The memory limit for the task, when reached the task will be automatically terminated
9999
Type: Number
100-
Default: 768
100+
Default: 512
101101
AllowedValues: [16, 32, 64, 128, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4096]
102102

103103
SplunkToken:

gradle/wrapper/gradle-wrapper.jar

1.72 KB
Binary file not shown.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

Dockerfile service/Dockerfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
FROM openjdk:8u181-jre-slim
1+
FROM openjdk:11.0.3-jre-slim
22

33
ARG JAR_FILE
44

55
RUN apt-get update && apt-get install -y wget
66

77
COPY ${JAR_FILE} app.jar
8-
RUN mkdir newrelic && wget https://download.newrelic.com/newrelic/java-agent/newrelic-agent/4.4.0/newrelic-agent-4.4.0.jar -O newrelic/newrelic.jar
8+
RUN mkdir newrelic && wget https://download.newrelic.com/newrelic/java-agent/newrelic-agent/4.12.1/newrelic-agent-4.12.1.jar -O newrelic/newrelic.jar
99
COPY newrelic.yml newrelic/newrelic.yml
1010

1111
EXPOSE 8080
1212

13-
ENTRYPOINT exec java $JAVA_OPTS -jar app.jar
13+
ENTRYPOINT exec java -XX:MaxRAMPercentage=80 -XX:+AlwaysPreTouch -XX:+UseStringDeduplication -Djava.security.egd=file:/dev/./urandom $JAVA_OPTS -jar app.jar
1414

1515
HEALTHCHECK --start-period=300s \
1616
CMD wget --quiet --tries=1 --spider --timeout=30 http://localhost:8080/actuator/health || exit 1

service/build.gradle

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
plugins {
2+
id "org.springframework.boot" version "2.1.4.RELEASE"
3+
id "io.spring.dependency-management" version "1.0.7.RELEASE"
4+
id "com.palantir.docker" version "0.21.0"
5+
id "com.gorylenko.gradle-git-properties" version "2.0.0"
6+
}
7+
8+
jar {
9+
baseName = rootProject.name + "-" + project.name
10+
}
11+
12+
springBoot {
13+
buildInfo()
14+
}
15+
16+
sonarqube {
17+
properties {
18+
property "sonar.projectKey", "${rootProject.name}:${project.name}"
19+
property "sonar.coverage.exclusions", "**/configuration/*"
20+
property "sonar.cpd.exclusions", "**/model/api/*,**/model/entity/*"
21+
}
22+
}
23+
24+
if (!project.hasProperty("REPOSITORY_URI")) {
25+
ext.REPOSITORY_URI = jar.baseName
26+
}
27+
28+
if (!project.hasProperty("TAG")) {
29+
ext.TAG = jar.version
30+
}
31+
32+
docker {
33+
name "${REPOSITORY_URI}"
34+
tags "${TAG}", 'latest'
35+
files bootJar.archivePath, "${project.projectDir.absolutePath}/config/newrelic/newrelic.yml"
36+
buildArgs(['JAR_FILE': "${bootJar.archiveName}"])
37+
}
38+
39+
dependencyManagement {
40+
imports {
41+
mavenBom "org.springframework.cloud:spring-cloud-sleuth:2.1.1.RELEASE"
42+
}
43+
}
44+
45+
dependencies {
46+
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
47+
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
48+
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth'
49+
implementation group: 'io.micrometer', name: 'micrometer-registry-new-relic', version: '1.1.4'
50+
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
51+
}
File renamed without changes.

src/main/java/com/bnc/sbjb/rest/Controller.java service/src/main/java/com/bnc/sbjb/rest/Controller.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
package com.bnc.sbjb.rest;
22

3-
import org.springframework.http.HttpStatus;
3+
import org.springframework.web.bind.annotation.GetMapping;
44
import org.springframework.web.bind.annotation.RequestMapping;
5-
import org.springframework.web.bind.annotation.ResponseStatus;
65
import org.springframework.web.bind.annotation.RestController;
76

87
@RestController
98
@RequestMapping("${resource.path}")
109
public class Controller {
1110

12-
@RequestMapping("/hello-error")
13-
@ResponseStatus(HttpStatus.OK)
11+
@GetMapping("/hello-error")
1412
public String notYetWorld() {
1513
throw new IllegalStateException("Hello World");
1614
}
1715

18-
@RequestMapping("/hello")
19-
@ResponseStatus(HttpStatus.OK)
16+
@GetMapping("/hello")
2017
public String helloWorld() {
2118
return "Hello World";
2219
}

0 commit comments

Comments
 (0)