2

i am trying to build a docker for my Java Spring MVC application and packages are managed by MAVEN.

my project folder view:

1)wc-aws(JAR)
    -pom.xml
    -src
2)wc-admin(spring project WAR)
    -pom.xml
    -src
3)wc-dao(JAR)
    -pom.xml
    -src
-pom.xml

my DockerFile

FROM maven:3.6.1-jdk-8 as maven_builder

ENV HOME=/app

RUN mkdir $HOME

WORKDIR $HOME

ADD . $HOME

RUN mvn dependency:go-offline

RUN mvn clean install -T 2C -DskipTests=true

FROM tomcat:8.5.43-jdk8

ENV HOME=/app

FROM tomcat:8.5.43-jdk8

COPY --from=maven_builder /app/wc-admin/target/wc-admin.war /usr/local/tomcat/webapps/ROOT

i get the following error :

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for wc-pom 1.0:
[INFO]
[INFO] wc-pom ............................................. SUCCESS [02:17 min]
[INFO] wc-commons ......................................... SUCCESS [02:56 min]
[INFO] wc-dao ............................................. FAILURE [ 13.308 s]
[INFO] wc-aws ............................................. SKIPPED
[INFO] wc-event ........................................... SKIPPED
[INFO] wc-mqueue .......................................... SKIPPED
[INFO] wc-admin ........................................... SKIPPED
[INFO] wc-ftp-download .................................... SKIPPED
[INFO] wc-content-transformation .......................... SKIPPED
[INFO] wc-content-notification ............................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  05:59 min
[INFO] Finished at: 2019-07-26T07:48:34Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project wc-dao: Could not resolve dependencies for project com.whitecoats:wc-dao:jar:1.0: Could not find artifact com.whitecoats:wc-commons:jar:1.0 in central (https://repo.maven.apache.org/maven2) -> [Help 1]

As you can see, the error is saying that, maven is looking for wc-dao in central and cannot find it.

but wc-dao is local java project and its JAR file is created in runtime.

how do i resolve it?

2 Answers2

1

The problem here is that when maven performs dependency:go-offline it looks for all dependencies including dependencies on the other modules in the project. But at the moment of running there are no built artifacts for the module-dependencies, because they have never been built. Read more here.

It is a known issue, at the same time, there is no solution except building the dependent modules first.

But in your particular case it is not possible (once you build the dependencies the command can't be cached by Docker).

A workaround: The dependency plugin has an option called excludeArtifactIds using which you can exclude some of the modules that do require modular dependencies. Having this, you will be able to resolve all dependencies except of those in the excluded modules.

mvn dependency:go-offline -DexcludeArtifactIds:wc-dao,some-other-artifact

The same way you can use excludeGroupIds if you want to exclude a group.

Of course, this way Docker won't cache all you wanted, but better to have something cached than nothing.

Sasha Shpota
  • 9,436
  • 14
  • 75
  • 148
0

Okay,

so to solve this problem, i used docker volumes:

docker run --rm -v <my-java-app>:/app -v <a folder to maven repository>:/root/.m2 -w /app maven:3.6-jdk-8 mvn clean install -T 2C -DskipTests=true

This is the best solution we will get presently.