Docker-compose build loads several pom dependencies each time

I use Heroku Java Docker Image and docker-compose to run the local Java-based dropwizard web service.

When I run the command docker-compose build webto create the code, it loads several dependencies each time. Thus, the processing time of the assembly process has increased.

My project docker file is just one line: FROM heroku/java

Here is the build log:

[INFO] ------------------------------------------------------------------------
[INFO] Building generator-app-server 0.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (4 KB at 0.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom (13 KB at 9.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar (25 KB at 14.7 KB/sec)
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ generator-app-server ---
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.pom (4 KB at 5.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/16/spice-parent-16.pom
Downloaded: https://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/16/spice-parent-16.pom (9 KB at 4.9 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/5/forge-parent-5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/5/forge-parent-5.pom (9 KB at 5.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar (221 KB at 20.0 KB/sec)
[INFO] Deleting /app/user/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ generator-app-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 7 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ generator-app-server ---
Downloading: https://repo.maven.apache.org/maven2/org/mapstruct/mapstruct-processor/1.1.0.Final/mapstruct-processor-1.1.0.Final.jar
Downloaded: https://repo.maven.apache.org/maven2/org/mapstruct/mapstruct-processor/1.1.0.Final/mapstruct-processor-1.1.0.Final.jar (1502 KB at 24.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/mapstruct/mapstruct-processor/1.1.0.Final/mapstruct-processor-1.1.0.Final.pom
Downloaded: https://repo.maven.apache.org/maven2/org/mapstruct/mapstruct-processor/1.1.0.Final/mapstruct-processor-1.1.0.Final.pom (12 KB at 4.9 KB/sec)

docker-compose builddoes not use cached dependencies for the above libraries. How to force cached dependencies?

Googled a lot, but no luck. Share if anyone collided and fixed.

Update:

Dockerfile
FROM heroku/java

docker-compose.yml
web:
  build: .
  command: 'bash -c ''java $JAVA_OPTS -jar target/generator-app-server-0.0.2-SNAPSHOT.jar db migrate config.yml && java $JAVA_OPTS -Ddw.server.connector.port=$PORT -jar target/generator-app-server-0.0.2-SNAPSHOT.jar server config.yml'''
  working_dir: /app/user
  environment:
    PORT: 8080
    DATABASE_URL: 'postgres://postgres:@herokuPostgresql:5432/postgres'
  ports:
    - '8080:8080'
  links:
    - herokuPostgresql
shell:
  build: .
  command: bash
  working_dir: /app/user
  environment:
    PORT: 8080
    DATABASE_URL: 'postgres://postgres:@herokuPostgresql:5432/postgres'
  ports:
    - '8080:8080'
  links:
    - herokuPostgresql
  volumes:
    - '.:/app/user'
herokuPostgresql:
  image: postgres
+4
1

( , Maven , ONBUILD). , .

, , Maven clean. Dockerfile https://github.com/heroku/docker-java/blob/master/Dockerfile#L14 ( POM). , Dockerfile, clean https://github.com/heroku/docker-java/blob/master/Dockerfile#L18. maven-clean-plugin POM, ( Dockerfile).

, maven-clean-plugin, POM ( <scope>import</scope>).

0

Source: https://habr.com/ru/post/1681287/


All Articles