Skip to content

Commit 82b87f5

Browse files
committed
- use gradle instead of maven
- upgrade to Spring Boot 2 - remove unused references - create postgres user (needed in newer versions of postgres image) - demonstrate test splitting
1 parent 54fa356 commit 82b87f5

32 files changed

+597
-197
lines changed

.circleci/config.yml

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,60 @@
11
version: 2
22
jobs:
33
build:
4-
5-
working_directory: ~/circleci-demo-java-spring
6-
4+
# Remove if parallelism is not desired
5+
parallelism: 2
6+
environment:
7+
# Configure the JVM and Gradle to avoid OOM errors
8+
_JAVA_OPTIONS: "-Xmx3g"
9+
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2"
710
docker:
8-
- image: circleci/openjdk:8-jdk-stretch
9-
- image: circleci/postgres:9.6.3-alpine
11+
- image: circleci/openjdk:11.0.3-jdk-stretch
12+
- image: circleci/postgres:12-alpine
1013
environment:
11-
POSTGRES_USER: root
14+
POSTGRES_USER: postgres
1215
POSTGRES_DB: circle_test
13-
1416
steps:
15-
1617
- checkout
17-
1818
- restore_cache:
19-
key: circleci-demo-java-spring-{{ checksum "pom.xml" }}
20-
21-
- run: mvn dependency:go-offline
22-
19+
key: v1-gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
20+
- restore_cache:
21+
key: v1-gradle-cache-{{ checksum "build.gradle" }}
22+
- run:
23+
name: Run tests in parallel
24+
# Use "./gradlew test" instead if tests are not run in parallel
25+
command: |
26+
cd src/test/java
27+
# Get list of classnames of tests that should run on this node
28+
CLASSNAMES=$(circleci tests glob "**/*.java" \
29+
| cut -c 1- | sed 's@/@.@g' \
30+
| sed 's/.\{5\}$//' \
31+
| circleci tests split --split-by=timings --timings-type=classname)
32+
cd ../../..
33+
# Format the arguments to "./gradlew test"
34+
GRADLE_ARGS=$(echo $CLASSNAMES | awk '{for (i=1; i<=NF; i++) print "--tests",$i}')
35+
echo "Prepared arguments for Gradle: $GRADLE_ARGS"
36+
./gradlew test $GRADLE_ARGS
2337
- save_cache:
2438
paths:
25-
- ~/.m2
26-
key: circleci-demo-java-spring-{{ checksum "pom.xml" }}
27-
28-
- run: mvn package
29-
39+
- ~/.gradle/wrapper
40+
key: v1-gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
41+
- save_cache:
42+
paths:
43+
- ~/.gradle/caches
44+
key: v1-gradle-cache-{{ checksum "build.gradle" }}
3045
- store_test_results:
31-
path: target/surefire-reports
32-
46+
path: build/test-results/test
3347
- store_artifacts:
34-
path: target/demo-java-spring-0.0.1-SNAPSHOT.jar
48+
path: build/test-results/test
49+
when: always
50+
- run:
51+
name: Assemble JAR
52+
command: |
53+
# Skip this for other nodes
54+
if [ "$CIRCLE_NODE_INDEX" == 0 ]; then
55+
./gradlew assemble
56+
fi
57+
# This will be empty for all nodes except the first one
58+
- store_artifacts:
59+
path: build/libs
60+

.gitignore

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
target/
2-
3-
pom.xml.tag
4-
pom.xml.releaseBackup
5-
pom.xml.versionsBackup
6-
pom.xml.next
7-
release.properties
8-
dependency-reduced-pom.xml
9-
buildNumber.properties
10-
.mvn/timing.properties
11-
12-
# Compiled class file
13-
*.class
14-
15-
# Log file
16-
*.log
17-
18-
# Package Files #
19-
*.jar
20-
*.war
21-
*.ear
22-
*.zip
23-
*.tar.gz
24-
*.rar
1+
HELP.md
2+
.gradle
3+
build/
4+
!gradle/wrapper/gradle-wrapper.jar
5+
!**/src/main/**
6+
!**/src/test/**
257

8+
### STS ###
9+
.apt_generated
2610
.classpath
11+
.factorypath
2712
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
17+
### IntelliJ IDEA ###
18+
.idea
19+
*.iws
20+
*.iml
21+
*.ipr
22+
out/
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
2830

29-
# Editor and IDE Specific
31+
### VS Code ###
3032
.vscode/
31-
.settings/
33+
bin/

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 CircleCI
3+
Copyright (c) 2019 CircleCI
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
1-
# CircleCI 2.0 Java Demo Application using Maven and Spring [![CI](https://circleci.com/gh/CircleCI-Public/circleci-demo-java-spring.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/CircleCI-Public/circleci-demo-java-spring)
1+
# CircleCI 2.0 Java Demo Application using Gradle and Spring [![CircleCI status](https://circleci.com/gh/CircleCI-Public/circleci-demo-java-spring.svg "CircleCI status")](https://circleci.com/gh/CircleCI-Public/circleci-demo-java-spring)
22

33
This is an example application showcasing how to run a Java app on CircleCI 2.0.
44

55
This application uses the following tools:
66

7-
* Maven
8-
* Java 8
9-
* PostgreSQL
10-
* Spring
7+
* Gradle
8+
* Java 11
9+
* PostgreSQL
10+
* Spring Boot
1111
* Thymeleaf
1212

1313
You can follow along with this project by reading the [documentation](https://circleci.com/docs/2.0/language-java/).
1414

15+
## Local Development
16+
17+
### Starting the application
18+
19+
Start up a PostgreSQL Database Docker container:
20+
21+
```
22+
docker run -e POSTGRES_USER=postgres -e POSTGRES_DB=circle_test -p 5432:5432 -itd circleci/postgres:12-alpine
23+
```
24+
25+
Start up the Java application:
26+
27+
```
28+
./gradlew bootRun
29+
```
30+
1531
## License
1632

17-
Copyright © 2017 CircleCI
33+
Copyright © 2019 CircleCI
1834

1935
Distributed under the MIT license, see the file LICENSE.

build.gradle

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
plugins {
2+
id 'org.springframework.boot' version '2.1.6.RELEASE'
3+
id 'java'
4+
}
5+
6+
apply plugin: 'io.spring.dependency-management'
7+
8+
group = 'com.circleci'
9+
version = '0.0.1-SNAPSHOT'
10+
sourceCompatibility = '1.11'
11+
12+
repositories {
13+
mavenCentral()
14+
}
15+
16+
// Currently only needed for spring-boot-devtools
17+
// https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html
18+
configurations {
19+
developmentOnly
20+
runtimeClasspath {
21+
extendsFrom developmentOnly
22+
}
23+
}
24+
25+
dependencies {
26+
implementation 'org.springframework.boot:spring-boot-starter-web'
27+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
28+
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
29+
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
30+
compile group: 'org.webjars', name: 'bootstrap', version: '3.3.7'
31+
runtime 'org.postgresql:postgresql:42.2.6'
32+
developmentOnly("org.springframework.boot:spring-boot-devtools")
33+
}

gradle/wrapper/gradle-wrapper.jar

54.3 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)