Skip to content

Commit fb851d0

Browse files
committed
Caching Maven Dependencies with Docker - improvements
1 parent 7f84f87 commit fb851d0

15 files changed

Lines changed: 107 additions & 103 deletions

File tree

docker/docker-caching/multi-module/Dockerfile renamed to docker/docker-caching/multi-module-caching/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ WORKDIR $HOME
55

66
ADD pom.xml $HOME
77
ADD core/pom.xml $HOME/core/pom.xml
8-
ADD application/pom.xml $HOME/application/pom.xml
8+
ADD runner/pom.xml $HOME/runner/pom.xml
99

1010
RUN mvn -pl core verify --fail-never
1111
ADD core $HOME/core
1212
RUN mvn -pl core install
13-
RUN mvn -pl application verify --fail-never
14-
ADD application $HOME/application
15-
RUN mvn -pl core,application package
13+
RUN mvn -pl runner verify --fail-never
14+
ADD runner $HOME/runner
15+
RUN mvn -pl core,runner package
1616

1717
FROM openjdk:8-jdk-alpine
1818

19-
COPY --from=build /usr/app/application/target/application-0.0.1-SNAPSHOT.jar /app/runner.jar
19+
COPY --from=build /usr/app/runner/target/runner-0.0.1-SNAPSHOT-jar-with-dependencies.jar /app/runner.jar
2020

2121
ENTRYPOINT java -jar /app/runner.jar

docker/docker-caching/multi-module/Dockerfile-Buildkit renamed to docker/docker-caching/multi-module-caching/Dockerfile-Buildkit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ RUN --mount=type=cache,target=/root/.m2 mvn -f $HOME/pom.xml clean package
88

99
FROM openjdk:8-jdk-alpine
1010

11-
COPY --from=build /usr/app/application/target/application-0.0.1-SNAPSHOT.jar /app/runner.jar
11+
COPY --from=build /usr/app/runner/target/runner-0.0.1-SNAPSHOT-jar-with-dependencies.jar /app/runner.jar
1212

1313
ENTRYPOINT java -jar /app/runner.jar

docker/docker-caching/multi-module/core/pom.xml renamed to docker/docker-caching/multi-module-caching/core/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<parent>
6-
<artifactId>maven-caching</artifactId>
6+
<artifactId>multi-module-caching</artifactId>
77
<groupId>com.baeldung</groupId>
88
<version>0.0.1-SNAPSHOT</version>
99
</parent>
@@ -16,4 +16,10 @@
1616
<maven.compiler.target>8</maven.compiler.target>
1717
</properties>
1818

19+
<dependencies>
20+
<dependency>
21+
<groupId>com.google.guava</groupId>
22+
<artifactId>guava</artifactId>
23+
</dependency>
24+
</dependencies>
1925
</project>

docker/docker-caching/multi-module/core/src/main/java/com/baeldung/maven_caching/CoreClass.java renamed to docker/docker-caching/multi-module-caching/core/src/main/java/com/baeldung/maven_caching/CoreClass.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package com.baeldung.maven_caching;
22

3+
import com.google.common.io.Files;
4+
35
public class CoreClass {
46

57
public String method(){
68
return "Hello from core module!!";
79
}
10+
11+
public String dependencyMethod(){
12+
return Files.simplifyPath("/home/app/test");
13+
}
814
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<packaging>pom</packaging>
6+
<modules>
7+
<module>runner</module>
8+
<module>core</module>
9+
</modules>
10+
<groupId>com.baeldung</groupId>
11+
<artifactId>multi-module-caching</artifactId>
12+
<version>0.0.1-SNAPSHOT</version>
13+
<name>maven-caching</name>
14+
<description>maven-caching</description>
15+
<properties>
16+
<java.version>1.8</java.version>
17+
</properties>
18+
19+
<dependencyManagement>
20+
<dependencies>
21+
<dependency>
22+
<groupId>com.google.guava</groupId>
23+
<artifactId>guava</artifactId>
24+
<version>31.0.1-jre</version>
25+
</dependency>
26+
</dependencies>
27+
</dependencyManagement>
28+
29+
</project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>multi-module-caching</artifactId>
7+
<groupId>com.baeldung</groupId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>runner</artifactId>
13+
<dependencies>
14+
<dependency>
15+
<groupId>com.baeldung</groupId>
16+
<artifactId>core</artifactId>
17+
<version>0.0.1-SNAPSHOT</version>
18+
</dependency>
19+
</dependencies>
20+
21+
<properties>
22+
<maven.compiler.source>8</maven.compiler.source>
23+
<maven.compiler.target>8</maven.compiler.target>
24+
</properties>
25+
26+
<build>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-assembly-plugin</artifactId>
31+
<version>3.3.0</version>
32+
<configuration>
33+
<descriptorRefs>
34+
<descriptorRef>jar-with-dependencies</descriptorRef>
35+
</descriptorRefs>
36+
<archive>
37+
<manifest>
38+
<addClasspath>true</addClasspath>
39+
<mainClass>com.baeldung.maven_caching.MavenCachingApplication</mainClass>
40+
</manifest>
41+
</archive>
42+
</configuration>
43+
<executions>
44+
<execution>
45+
<id>assemble-all</id>
46+
<phase>package</phase>
47+
<goals>
48+
<goal>single</goal>
49+
</goals>
50+
</execution>
51+
</executions>
52+
</plugin>
53+
</plugins>
54+
</build>
55+
</project>

docker/docker-caching/multi-module/application/src/main/java/com/baeldung/maven_caching/MavenCachingApplication.java renamed to docker/docker-caching/multi-module-caching/runner/src/main/java/com/baeldung/maven_caching/MavenCachingApplication.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package com.baeldung.maven_caching;
22

3-
import org.springframework.boot.SpringApplication;
4-
import org.springframework.boot.autoconfigure.SpringBootApplication;
5-
6-
@SpringBootApplication
73
public class MavenCachingApplication {
84

95
public static void main(String[] args) {
10-
SpringApplication.run(MavenCachingApplication.class, args);
116
CoreClass cc = new CoreClass();
127
System.out.println(cc.method());
8+
System.out.println(cc.dependencyMethod());
139
}
1410

1511
}

docker/docker-caching/multi-module/application/pom.xml

Lines changed: 0 additions & 36 deletions
This file was deleted.

docker/docker-caching/multi-module/application/src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

docker/docker-caching/multi-module/application/src/test/java/com/baeldung/maven_caching/MavenCachingApplicationTests.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)