And that also means we have to define a custom task
Matthias Grüter
@mattgruter
Wouldn't something like:
copy {
from jar
into stageDir
}
work?
Dave Syer
@dsyer
and that it has to be deferred with "<<"
I'm not a gradler. Happy to take edits.
Where does that go?
Inside the task definition?
Matthias Grüter
@mattgruter
Yes, instead of the new File(stageDir, jar.archiveName).bytes = jar.archivePath.bytes
Dave Syer
@dsyer
Trying it...
Dave Syer
@dsyer
I don't think that worked
the image it builds has the same ID as docker/java
Actually that's a problem with the "<<" (cc @gregturn)
Matthias Grüter
@mattgruter
Exactly. The dockerfile, applicationName and push properties have to be defined in the configuration phase of the build not the execution phase (with the "<<" you push everything into the execution phase)
Dave Syer
@dsyer
Yeah. I'm unhacking that now.
Then the copy{} works, thanks
Matthias Grüter
@mattgruter
This should work:
task buildDocker(type: Docker, dependsOn: jar) {
push = false
applicationName = jar.baseName
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
Dave Syer
@dsyer
@gregturn thought he found a problem that meant he had to defer to execution
It works for me though
Actually that doesn't
You have to "dependsOn: build"
(which I assumed would be the default - haven't tried that yet)
How come I have to explicitly create a java.io.File() for the dockerfile BTW?
Yeah you need "dependsOn: build"
but the copy actually doesn't work
_
doFirst
Missed that
I hate gradle sometimes
Do you think we could make this use case more mainstream in the plugin? That would help idiots like me.
yeah, the configuration<>execution build lifecycle stuff is quite confusing in gradle IMO. many bugs lurking there... :-)
Dave Syer
@dsyer
It works now for me anyway, thank you.
Matthias Grüter
@mattgruter
why doesn't dependsOn: jar not work?
Dave Syer
@dsyer
Because the jar that is executable is not built by the gradle "jar" task
It is built by "bootRepackage" (so we could depend on that I guess)
Matthias Grüter
@mattgruter
That would be better, because the task build depends on tests and other findbugs, etc.
Dave Syer
@dsyer
I would expect to want to run tests etc before pushing a container image
It seems like the "last step" in a CI build to me
Matthias Grüter
@mattgruter
True. However, I tend to see buildDocker as a "assembly" step. build then ties together assembly and tests tasks.
Dave Syer
@dsyer
I see.
In which case we will need a custom task here whatever you do in the plugin
Matthias Grüter
@mattgruter
That's mostly a question of taste though. So dependsOn: build is definately ok, especially in a tutorial (short & conscise to read!)
But yeah in general, we should make your use-case more straight-forward with the plugin.
Dave Syer
@dsyer
because the plugin will never know that its default task should depend on something from another plugin that it doesn't require already
Matthias Grüter
@mattgruter
the plugin only creates a default task if the application plugin is used as well.
otherwise it doesn't create a task on its own
Dave Syer
@dsyer
I see. Well, somewhat accidentally, and for historical reasons, the "spring-boot" plugin also adds the "application" plugin
So that's always there in this use case
Matthias Grüter
@mattgruter
we recently started using spring-boot at work here so we'll be adding some more convenience into the plugin one way or the other. can't tell you when though... :-)