per-warm the maven cache for 2 stage Docker build

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

per-warm the maven cache for 2 stage Docker build

Adam Sandor
I’m trying to figure out how to create a two-stage Docker build using Maven
that would properly utilise Docker layer caching. Containing the whole
build in a Docker container without external dependencies on volume mounts
(for .m2 cache) has a lot of advantages.
The only missing piece of the puzzle I can’t figure out is how to force
Maven to download ALL dependencies just by using the pom file and not
executing any compilation. The idea behind is to:
1. copy the pom file into the image
2. use maven to download all dependencies
3. copy the sources to the image
4. use maven to build the final artifact
This way Docker will reuse the layer containing the dependencies if the pom
file didn’t change. So dependency caching would be implemented in a
Docker-ish way that works anywhere the Docker daemon is present as opposed
to relying on Maven being installed and artifacts getting stored in a
shared .m2/repository directory.

Now the problem - Maven’s lazy downloading of dependencies. Even if I try
to execute “mvn dependency:go-offline” Maven still doesn’t download plugins
and other dependencies, which would only be required during the packaging
phase. So the following Docker file doesn’t work as intended:

FROM maven AS build
WORKDIR /build
ADD pom.xml /build
RUN mvn dependency:go-offline
ADD src /build/src
RUN mvn -o package
FROM openjdk:8-jdk
WORKDIR /app
COPY --from=build /build/target/app.jar /app
CMD java -jar /app/app.jar

Maven will still start downloading more dependencies on line 6.

I found a workaround for this - execute “mvn package” with a single fake
main class on line 4, but this is not a nice solution. Can anyone give me
some option I’m missing or confirm that this is the way things are? In that
case I can go ahead write a blog post showing my workaround to help other
struggling with the same problem. Thank you!

Adam Sandor from Container Solutions


--

Ádám Sándor

Senior Engineer / Consultant

Container Solutions <http://container-solutions.com/>

0680126174

<https://twitter.com/adamsand0r> <https://www.linkedin.com/in/adamsandor/>
Reply | Threaded
Open this post in threaded view
|

Re: per-warm the maven cache for 2 stage Docker build

Adam Sandor
Hello Maven people,

Can someone at least give me some feedback on why this one is not
getting any answers? Asked the question in a wrong way? Is it not
clear? Not interesting?

I think supporting Docker-based builds is very important today. I'm
thinking of contributing code to solve this issue, but I first want to
confirm I didn't miss some solution that is already available.

Adam

On Sun, Feb 4, 2018 at 12:57 PM, Adam Sandor
<[hidden email]> wrote:

> I’m trying to figure out how to create a two-stage Docker build using Maven
> that would properly utilise Docker layer caching. Containing the whole build
> in a Docker container without external dependencies on volume mounts (for
> .m2 cache) has a lot of advantages.
> The only missing piece of the puzzle I can’t figure out is how to force
> Maven to download ALL dependencies just by using the pom file and not
> executing any compilation. The idea behind is to:
> 1. copy the pom file into the image
> 2. use maven to download all dependencies
> 3. copy the sources to the image
> 4. use maven to build the final artifact
> This way Docker will reuse the layer containing the dependencies if the pom
> file didn’t change. So dependency caching would be implemented in a
> Docker-ish way that works anywhere the Docker daemon is present as opposed
> to relying on Maven being installed and artifacts getting stored in a shared
> .m2/repository directory.
>
> Now the problem - Maven’s lazy downloading of dependencies. Even if I try to
> execute “mvn dependency:go-offline” Maven still doesn’t download plugins and
> other dependencies, which would only be required during the packaging phase.
> So the following Docker file doesn’t work as intended:
>
> FROM maven AS build
> WORKDIR /build
> ADD pom.xml /build
> RUN mvn dependency:go-offline
> ADD src /build/src
> RUN mvn -o package
> FROM openjdk:8-jdk
> WORKDIR /app
> COPY --from=build /build/target/app.jar /app
> CMD java -jar /app/app.jar
>
> Maven will still start downloading more dependencies on line 6.
>
> I found a workaround for this - execute “mvn package” with a single fake
> main class on line 4, but this is not a nice solution. Can anyone give me
> some option I’m missing or confirm that this is the way things are? In that
> case I can go ahead write a blog post showing my workaround to help other
> struggling with the same problem. Thank you!
>
> Adam Sandor from Container Solutions
>
>
> --
>
> Ádám Sándor
>
> Senior Engineer / Consultant
>
> Container Solutions
>
> 0680126174

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: per-warm the maven cache for 2 stage Docker build

Hervé BOUTEMY
Le lundi 19 février 2018, 09:25:13 CET Adam Sandor a écrit :
> Hello Maven people,
>
> Can someone at least give me some feedback on why this one is not
> getting any answers? Asked the question in a wrong way? Is it not
> clear? Not interesting?
I suppose this is a mix that not many people are fluent with
I'll try to help.

>
> I think supporting Docker-based builds is very important today. I'm
> thinking of contributing code to solve this issue, but I first want to
> confirm I didn't miss some solution that is already available.
>
> Adam
>
> On Sun, Feb 4, 2018 at 12:57 PM, Adam Sandor
>
> <[hidden email]> wrote:
> > I’m trying to figure out how to create a two-stage Docker build using
> > Maven
> > that would properly utilise Docker layer caching. Containing the whole
> > build in a Docker container without external dependencies on volume
> > mounts (for .m2 cache) has a lot of advantages.
> > The only missing piece of the puzzle I can’t figure out is how to force
> > Maven to download ALL dependencies just by using the pom file and not
> > executing any compilation. The idea behind is to:
> > 1. copy the pom file into the image
> > 2. use maven to download all dependencies
> > 3. copy the sources to the image
> > 4. use maven to build the final artifact
> > This way Docker will reuse the layer containing the dependencies if the
> > pom
> > file didn’t change. So dependency caching would be implemented in a
> > Docker-ish way that works anywhere the Docker daemon is present as opposed
> > to relying on Maven being installed and artifacts getting stored in a
> > shared .m2/repository directory.
> >
> > Now the problem - Maven’s lazy downloading of dependencies. Even if I try
> > to execute “mvn dependency:go-offline” Maven still doesn’t download
> > plugins and other dependencies, which would only be required during the
> > packaging phase.
Maven Dependency Plugin is supposed to download plugins: that's surprising you
don't get one plugin downloaded.
There is one classical cause I imagine: did you define a version for every
plugin used?
You should be able to have a diagnostic through "mvn versions:display-plugin-
updates"

Regards,

Hervé


> > So the following Docker file doesn’t work as intended:
> >
> > FROM maven AS build
> > WORKDIR /build
> > ADD pom.xml /build
> > RUN mvn dependency:go-offline
> > ADD src /build/src
> > RUN mvn -o package
> > FROM openjdk:8-jdk
> > WORKDIR /app
> > COPY --from=build /build/target/app.jar /app
> > CMD java -jar /app/app.jar
> >
> > Maven will still start downloading more dependencies on line 6.
> >
> > I found a workaround for this - execute “mvn package” with a single fake
> > main class on line 4, but this is not a nice solution. Can anyone give me
> > some option I’m missing or confirm that this is the way things are? In
> > that
> > case I can go ahead write a blog post showing my workaround to help other
> > struggling with the same problem. Thank you!
> >
> > Adam Sandor from Container Solutions
> >
> >
> > --
> >
> > Ádám Sándor
> >
> > Senior Engineer / Consultant
> >
> > Container Solutions
> >
> > 0680126174
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: per-warm the maven cache for 2 stage Docker build

Adam Sandor
Hi Herve,

Thank you very much for taking a look at this. Unfortunately running
"versions:display-plugin-updates" says all plugins have a version
specified. My pom file is practically empty - it's a tiny spring boot app (
https://github.com/adam-sandor/memoryhog/blob/master/pom.xml).
Any other ideas?

Here is the output of the version plugin, and here you can see the output
of "mvn package" after "mvn dependency:go-offline" has already ran:
https://gist.github.com/adam-sandor/9296560d8bdae3f77f6b1160c0635e55

[INFO]
[INFO] All plugins with a version specified are using the latest versions.
[INFO]
[INFO] All plugins have a version specified.
[INFO]

On Mon, Feb 19, 2018 at 5:46 PM Hervé BOUTEMY <[hidden email]> wrote:

> Le lundi 19 février 2018, 09:25:13 CET Adam Sandor a écrit :
> > Hello Maven people,
> >
> > Can someone at least give me some feedback on why this one is not
> > getting any answers? Asked the question in a wrong way? Is it not
> > clear? Not interesting?
> I suppose this is a mix that not many people are fluent with
> I'll try to help.
>
> >
> > I think supporting Docker-based builds is very important today. I'm
> > thinking of contributing code to solve this issue, but I first want to
> > confirm I didn't miss some solution that is already available.
> >
> > Adam
> >
> > On Sun, Feb 4, 2018 at 12:57 PM, Adam Sandor
> >
> > <[hidden email]> wrote:
> > > I’m trying to figure out how to create a two-stage Docker build using
> > > Maven
> > > that would properly utilise Docker layer caching. Containing the whole
> > > build in a Docker container without external dependencies on volume
> > > mounts (for .m2 cache) has a lot of advantages.
> > > The only missing piece of the puzzle I can’t figure out is how to force
> > > Maven to download ALL dependencies just by using the pom file and not
> > > executing any compilation. The idea behind is to:
> > > 1. copy the pom file into the image
> > > 2. use maven to download all dependencies
> > > 3. copy the sources to the image
> > > 4. use maven to build the final artifact
> > > This way Docker will reuse the layer containing the dependencies if the
> > > pom
> > > file didn’t change. So dependency caching would be implemented in a
> > > Docker-ish way that works anywhere the Docker daemon is present as
> opposed
> > > to relying on Maven being installed and artifacts getting stored in a
> > > shared .m2/repository directory.
> > >
> > > Now the problem - Maven’s lazy downloading of dependencies. Even if I
> try
> > > to execute “mvn dependency:go-offline” Maven still doesn’t download
> > > plugins and other dependencies, which would only be required during the
> > > packaging phase.
> Maven Dependency Plugin is supposed to download plugins: that's surprising
> you
> don't get one plugin downloaded.
> There is one classical cause I imagine: did you define a version for every
> plugin used?
> You should be able to have a diagnostic through "mvn
> versions:display-plugin-
> updates"
>
> Regards,
>
> Hervé
>
>
> > > So the following Docker file doesn’t work as intended:
> > >
> > > FROM maven AS build
> > > WORKDIR /build
> > > ADD pom.xml /build
> > > RUN mvn dependency:go-offline
> > > ADD src /build/src
> > > RUN mvn -o package
> > > FROM openjdk:8-jdk
> > > WORKDIR /app
> > > COPY --from=build /build/target/app.jar /app
> > > CMD java -jar /app/app.jar
> > >
> > > Maven will still start downloading more dependencies on line 6.
> > >
> > > I found a workaround for this - execute “mvn package” with a single
> fake
> > > main class on line 4, but this is not a nice solution. Can anyone give
> me
> > > some option I’m missing or confirm that this is the way things are? In
> > > that
> > > case I can go ahead write a blog post showing my workaround to help
> other
> > > struggling with the same problem. Thank you!
> > >
> > > Adam Sandor from Container Solutions
> > >
> > >
> > > --
> > >
> > > Ádám Sándor
> > >
> > > Senior Engineer / Consultant
> > >
> > > Container Solutions
> > >
> > > 0680126174
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: per-warm the maven cache for 2 stage Docker build

Dan Pungă
Hello Adam!

I'm just coming from configuring pretty much what yu're trying to
achieve, but on OpenShift (which uses Docker, but it comes with a higher
level of orchestration).

 From what I understand, you're trying to achieve a 2-stage deploy of
your app, where you want to separate the "building" from the "running"
into two separate phases/containers.
If that's the case, I've come across this article that helped me
understand the 2-stage build "pattern":
https://codefresh.io/docker-tutorial/java_docker_pipeline/ the "Maven
Builder Docker image" paragraph.

I have tested a version for my app with docker and yes, there is a
problem with the lazy download if you're only using the pom.xml inside
the builder image.
Since you're binding the pom.xml (which is app specific, I'm guessing),
why not copy and build the entire app at the build stage for the docker
image? Not really an elegant solution here, but it works for incremental
builds when the pom doesn't change. If you're trying to achieve an
"universal" maven-builder-image with Docker, I guess external volume for
the repository would be the way, because the actual builder image is
volatile (ran with the --rm argument) so it doesn't store anything
except that which was created at build time.

As I mentioned, my final goal was getting it to work under OpenShift
which has an extra set of options to do that, so I haven't really tested
it further under Docker alone.
What OpenShift does, is integrate a tool/project that's called Source to
Image : https://github.com/openshift/source-to-image
If you're not bound by the tools you need to use (so Docker alone), I
guess it's worth looking into this. What this tool does is integrate
with the Docker image and injects data/runs parametrization specified in
a set of standard scripts: "save-artifacts" (which is of interest with
your current issue), "assemble" (where you specify the steps for the
build/deploy) and "run" (which defines how to start the running
instance/image after all was set).

Disclaimer: I'm not a certified/experienced Docker guy! Have thought
about giving my two cents around this issue, as I've came across it
quite recently too.

On 20.02.2018 13:22, Adam Sandor wrote:

> Hi Herve,
>
> Thank you very much for taking a look at this. Unfortunately running
> "versions:display-plugin-updates" says all plugins have a version
> specified. My pom file is practically empty - it's a tiny spring boot app (
> https://github.com/adam-sandor/memoryhog/blob/master/pom.xml).
> Any other ideas?
>
> Here is the output of the version plugin, and here you can see the output
> of "mvn package" after "mvn dependency:go-offline" has already ran:
> https://gist.github.com/adam-sandor/9296560d8bdae3f77f6b1160c0635e55
>
> [INFO]
> [INFO] All plugins with a version specified are using the latest versions.
> [INFO]
> [INFO] All plugins have a version specified.
> [INFO]
>
> On Mon, Feb 19, 2018 at 5:46 PM Hervé BOUTEMY <[hidden email]> wrote:
>
>> Le lundi 19 février 2018, 09:25:13 CET Adam Sandor a écrit :
>>> Hello Maven people,
>>>
>>> Can someone at least give me some feedback on why this one is not
>>> getting any answers? Asked the question in a wrong way? Is it not
>>> clear? Not interesting?
>> I suppose this is a mix that not many people are fluent with
>> I'll try to help.
>>
>>> I think supporting Docker-based builds is very important today. I'm
>>> thinking of contributing code to solve this issue, but I first want to
>>> confirm I didn't miss some solution that is already available.
>>>
>>> Adam
>>>
>>> On Sun, Feb 4, 2018 at 12:57 PM, Adam Sandor
>>>
>>> <[hidden email]> wrote:
>>>> I’m trying to figure out how to create a two-stage Docker build using
>>>> Maven
>>>> that would properly utilise Docker layer caching. Containing the whole
>>>> build in a Docker container without external dependencies on volume
>>>> mounts (for .m2 cache) has a lot of advantages.
>>>> The only missing piece of the puzzle I can’t figure out is how to force
>>>> Maven to download ALL dependencies just by using the pom file and not
>>>> executing any compilation. The idea behind is to:
>>>> 1. copy the pom file into the image
>>>> 2. use maven to download all dependencies
>>>> 3. copy the sources to the image
>>>> 4. use maven to build the final artifact
>>>> This way Docker will reuse the layer containing the dependencies if the
>>>> pom
>>>> file didn’t change. So dependency caching would be implemented in a
>>>> Docker-ish way that works anywhere the Docker daemon is present as
>> opposed
>>>> to relying on Maven being installed and artifacts getting stored in a
>>>> shared .m2/repository directory.
>>>>
>>>> Now the problem - Maven’s lazy downloading of dependencies. Even if I
>> try
>>>> to execute “mvn dependency:go-offline” Maven still doesn’t download
>>>> plugins and other dependencies, which would only be required during the
>>>> packaging phase.
>> Maven Dependency Plugin is supposed to download plugins: that's surprising
>> you
>> don't get one plugin downloaded.
>> There is one classical cause I imagine: did you define a version for every
>> plugin used?
>> You should be able to have a diagnostic through "mvn
>> versions:display-plugin-
>> updates"
>>
>> Regards,
>>
>> Hervé
>>
>>
>>>> So the following Docker file doesn’t work as intended:
>>>>
>>>> FROM maven AS build
>>>> WORKDIR /build
>>>> ADD pom.xml /build
>>>> RUN mvn dependency:go-offline
>>>> ADD src /build/src
>>>> RUN mvn -o package
>>>> FROM openjdk:8-jdk
>>>> WORKDIR /app
>>>> COPY --from=build /build/target/app.jar /app
>>>> CMD java -jar /app/app.jar
>>>>
>>>> Maven will still start downloading more dependencies on line 6.
>>>>
>>>> I found a workaround for this - execute “mvn package” with a single
>> fake
>>>> main class on line 4, but this is not a nice solution. Can anyone give
>> me
>>>> some option I’m missing or confirm that this is the way things are? In
>>>> that
>>>> case I can go ahead write a blog post showing my workaround to help
>> other
>>>> struggling with the same problem. Thank you!
>>>>
>>>> Adam Sandor from Container Solutions
>>>>
>>>>
>>>> --
>>>>
>>>> Ádám Sándor
>>>>
>>>> Senior Engineer / Consultant
>>>>
>>>> Container Solutions
>>>>
>>>> 0680126174
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>

Reply | Threaded
Open this post in threaded view
|

Re: per-warm the maven cache for 2 stage Docker build

ljnelson
In reply to this post by Adam Sandor
On Sun, Feb 4, 2018 at 3:58 AM Adam Sandor <
[hidden email]> wrote:

> The only missing piece of the puzzle I can’t figure out is how to force
> Maven to download ALL dependencies just by using the pom file and not
> executing any compilation.

[snip]

> Now the problem - Maven’s lazy downloading of dependencies. Even if I try
> to execute “mvn dependency:go-offline” Maven still doesn’t download plugins
> and other dependencies, which would only be required during the packaging
> phase.
>

I dimly recall that if you just do:

mvn dependency:go-offline

…you end up running version 2.8.something of the maven-dependency-plugin.
Its most recent version is 3.0.2.  I also seem to remember that this fixed
the issue you describe above.  Maybe try:

mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:go-offline

…?  Good luck.

Best,
Laird
Reply | Threaded
Open this post in threaded view
|

Re: per-warm the maven cache for 2 stage Docker build

Adam Sandor
Thank you all for the helpful answers. Some of the articles linked does
indeed have a working solution - using "mvn install" instead of "mvn
dependency:go-offline". That way everything gets downloaded. The reason
that wasn't working for me was, that I'm using the Spring Boot plugin which
looks for a main class - so it cannot be run on a pom file with no sources.
I'm still wondering however about the contract for dependency:go-offline...
how can you go-offline if only a part of your dependencies get's cached and
as soon as you try to run install you will run into missing deps?
So the question of the day (maybe worth another thread) is "Isn't mvn
dependency:go-offline supposed to download all dependencies?"

On Tue, Feb 20, 2018 at 7:37 PM Laird Nelson <[hidden email]> wrote:

> On Sun, Feb 4, 2018 at 3:58 AM Adam Sandor <
> [hidden email]> wrote:
>
> > The only missing piece of the puzzle I can’t figure out is how to force
> > Maven to download ALL dependencies just by using the pom file and not
> > executing any compilation.
>
> [snip]
>
> > Now the problem - Maven’s lazy downloading of dependencies. Even if I try
> > to execute “mvn dependency:go-offline” Maven still doesn’t download
> plugins
> > and other dependencies, which would only be required during the packaging
> > phase.
> >
>
> I dimly recall that if you just do:
>
> mvn dependency:go-offline
>
> …you end up running version 2.8.something of the maven-dependency-plugin.
> Its most recent version is 3.0.2.  I also seem to remember that this fixed
> the issue you describe above.  Maybe try:
>
> mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:go-offline
>
> …?  Good luck.
>
> Best,
> Laird
>
--

Ádám Sándor

Senior Engineer / Consultant

Container Solutions <http://container-solutions.com/>

0680126174

<https://twitter.com/adamsand0r> <https://www.linkedin.com/in/adamsandor/>
Reply | Threaded
Open this post in threaded view
|

Re: per-warm the maven cache for 2 stage Docker build

Christofer Dutz
Hi,

When creating a maven plugin for the Edgent project, I also setup an integration-test
That allows me to test the functionality of the plugin. I used the mrm-maven-plugin and the maven-invoker-plugin to get a dedicated local maven repo that is filled with all artifacts pulled in during the build. Eventually it might help you with your problem.

Just have a look at this build:
https://github.com/apache/incubator-edgent/tree/develop/utils/edgent-deployment-filter-maven-plugin

Chris


Am 05.03.18, 09:37 schrieb "Adam Sandor" <[hidden email]>:

    Thank you all for the helpful answers. Some of the articles linked does
    indeed have a working solution - using "mvn install" instead of "mvn
    dependency:go-offline". That way everything gets downloaded. The reason
    that wasn't working for me was, that I'm using the Spring Boot plugin which
    looks for a main class - so it cannot be run on a pom file with no sources.
    I'm still wondering however about the contract for dependency:go-offline...
    how can you go-offline if only a part of your dependencies get's cached and
    as soon as you try to run install you will run into missing deps?
    So the question of the day (maybe worth another thread) is "Isn't mvn
    dependency:go-offline supposed to download all dependencies?"
   
    On Tue, Feb 20, 2018 at 7:37 PM Laird Nelson <[hidden email]> wrote:
   
    > On Sun, Feb 4, 2018 at 3:58 AM Adam Sandor <
    > [hidden email]> wrote:
    >
    > > The only missing piece of the puzzle I can’t figure out is how to force
    > > Maven to download ALL dependencies just by using the pom file and not
    > > executing any compilation.
    >
    > [snip]
    >
    > > Now the problem - Maven’s lazy downloading of dependencies. Even if I try
    > > to execute “mvn dependency:go-offline” Maven still doesn’t download
    > plugins
    > > and other dependencies, which would only be required during the packaging
    > > phase.
    > >
    >
    > I dimly recall that if you just do:
    >
    > mvn dependency:go-offline
    >
    > …you end up running version 2.8.something of the maven-dependency-plugin.
    > Its most recent version is 3.0.2.  I also seem to remember that this fixed
    > the issue you describe above.  Maybe try:
    >
    > mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:go-offline
    >
    > …?  Good luck.
    >
    > Best,
    > Laird
    >
    --
   
    Ádám Sándor
   
    Senior Engineer / Consultant
   
    Container Solutions <http://container-solutions.com/>
   
    0680126174
   
    <https://twitter.com/adamsand0r> <https://www.linkedin.com/in/adamsandor/>
   


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: per-warm the maven cache for 2 stage Docker build

Adam Sandor
Hi Chris,

Thank you, that's very helpful. To give a bit more context here - I'm
searching for the *right* way to do Maven builds in a multi-stage Docker
environment. This means I don't want to go into such elaborate workarounds.
I have to end up with a very clean build which I can blog about to show how
to properly do multi-stage Dockers builds with Java. Basically I'm
searching for the equivalent of doing "npm install". I think it is very
important that Maven would support these builds in an elegant way without
any workarounds as multi-stage Docker builds might be the future of CI
environments.

Adam

On Mon, Mar 5, 2018 at 9:58 AM Christofer Dutz <[hidden email]>
wrote:

> Hi,
>
> When creating a maven plugin for the Edgent project, I also setup an
> integration-test
> That allows me to test the functionality of the plugin. I used the
> mrm-maven-plugin and the maven-invoker-plugin to get a dedicated local
> maven repo that is filled with all artifacts pulled in during the build.
> Eventually it might help you with your problem.
>
> Just have a look at this build:
>
> https://github.com/apache/incubator-edgent/tree/develop/utils/edgent-deployment-filter-maven-plugin
>
> Chris
>
>
> Am 05.03.18, 09:37 schrieb "Adam Sandor" <
> [hidden email]>:
>
>     Thank you all for the helpful answers. Some of the articles linked does
>     indeed have a working solution - using "mvn install" instead of "mvn
>     dependency:go-offline". That way everything gets downloaded. The reason
>     that wasn't working for me was, that I'm using the Spring Boot plugin
> which
>     looks for a main class - so it cannot be run on a pom file with no
> sources.
>     I'm still wondering however about the contract for
> dependency:go-offline...
>     how can you go-offline if only a part of your dependencies get's
> cached and
>     as soon as you try to run install you will run into missing deps?
>     So the question of the day (maybe worth another thread) is "Isn't mvn
>     dependency:go-offline supposed to download all dependencies?"
>
>     On Tue, Feb 20, 2018 at 7:37 PM Laird Nelson <[hidden email]>
> wrote:
>
>     > On Sun, Feb 4, 2018 at 3:58 AM Adam Sandor <
>     > [hidden email]> wrote:
>     >
>     > > The only missing piece of the puzzle I can’t figure out is how to
> force
>     > > Maven to download ALL dependencies just by using the pom file and
> not
>     > > executing any compilation.
>     >
>     > [snip]
>     >
>     > > Now the problem - Maven’s lazy downloading of dependencies. Even
> if I try
>     > > to execute “mvn dependency:go-offline” Maven still doesn’t download
>     > plugins
>     > > and other dependencies, which would only be required during the
> packaging
>     > > phase.
>     > >
>     >
>     > I dimly recall that if you just do:
>     >
>     > mvn dependency:go-offline
>     >
>     > …you end up running version 2.8.something of the
> maven-dependency-plugin.
>     > Its most recent version is 3.0.2.  I also seem to remember that this
> fixed
>     > the issue you describe above.  Maybe try:
>     >
>     > mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:go-offline
>     >
>     > …?  Good luck.
>     >
>     > Best,
>     > Laird
>     >
>     --
>
>     Ádám Sándor
>
>     Senior Engineer / Consultant
>
>     Container Solutions <http://container-solutions.com/>
>
>     0680126174
>
>     <https://twitter.com/adamsand0r> <
> https://www.linkedin.com/in/adamsandor/>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
Reply | Threaded
Open this post in threaded view
|

Re: per-warm the maven cache for 2 stage Docker build

Mirko Friedenhagen-2
Hello Adam,

as stated on the goal page[0] dependency:go-offline "Requires
dependency resolution of artifacts in scope: test". In multi-module
projects it might even fail because of unresolvable SNAPSHOT modules
of the current reactor.

I use this shell script (I call it mvn-go-offline):
--- snip ---
#!/bin/sh
# DESC: Try to download everything needed for building/testing the project.
MVN=${MVN:-mvn}
VERSION=3.0.2
PLUGIN=org.apache.maven.plugins:maven-dependency-plugin:${VERSION}
exec ${MVN} -e -V $* $PLUGIN:resolve-plugins $PLUGIN:go-offline $PLUGIN:sources
--- snap ---
and call e.g. `mvn-go-offline test-compile`.

Regards
Mirko

[0] https://maven.apache.org/plugins/maven-dependency-plugin/go-offline-mojo.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]