After learning from gitflow-incremental-builder how to remove
modules from mavenSession if we want to skip them
I implemented a 'version as a hash of sources and dependency
tree" solution:
https://github.com/avodonosov/hashver-maven-plugin
It relies on using property expressions as versions.
A build extension loads values for those properties from a file.
This can be a file with "normal" maven versions maintained
manually in source control or a file generated by the "hashver"
mojo when user wants to use the hash versions and avoid
build of unchanged modules. The extension allows to skip
module build if the artifact of the same version exists.
Using property expressions for versions has two drawbacks:
1. Calculation of hash versions should be a separate maven
invocation, it can't be done in the same maven session
as the main goal, because calculating the hash versions
requires building the dependency tree, and after dependency
tree is built it's impossible (I believe) to inject newly calculated
versions into the maven structures so that they are in effect
when the main goal is executed.
2. This approach is a bit intrusive - user needs to adjust
his pom.xml files to use property expressions in place
of versions.
The advantage of this approach is that maven downloads
artifacts of the skipped modules automatically if this module
is a dependency of a changed module.
If it was possible to annotate artifacts with the "src hash"
using some attribute other the version, and hook into
the artifact download maven logic to find artifacts by this
attribute then generation of hash versions could be done
in the same session as the main goal, and probably
the solution could be applied without any modifications
of user's pom.
I noticed, when uploading snapshot artifacts maven
adds a timestamp (and a sequential "build number"?)
to the artifact name. And when resolving artifacts,
special versionResolver object is invoked, which
for SNAPSHOT sends a metadata request
to the repository to retrieve a real, timestamped
name of the artifact corresponding tot to the snapshot.
This logic could be adjusted to use the "src hash"
instead of the timestamp, and lookup in the remote
repo an artifact matching the current module's
"src hash". Any advice on how to do that?
In the long run, I believe it is desirable for maven
to natively support the notion of "build inputs hash"
for modules and artifacts. It allows significant build
time savings and still be very deterministic and stable.
05.02.2020, 01:26, "Jason Young" <[email protected]>:
> Good questions. First of all, this plugin is CI-agnostic, but it does
> require the project to exist in a `git` repository, whether that is in CI
> or on your machine. Check the github page I linked to for more instructions
> on how it determines what projects in a reactor are considered "changed"
> and need to be built versus which are not changed and will be omitted from
> the reactor.
>
> In every Maven build, every dependency is checked this way:
>
> 1. If it is a project in the reactor, use the artifact of that project.
> 2. Otherwise, if the artifact is in the local repo, is that artifact.
> 3. Last resort: Download from the remote repository.
>
> There are some other rules omitted above, e.g. when to download a fresh
> SNAPSHOT artifact based on your chosen snapshot policy, etc., but that's
> the gist of it: Maven will obtain the artifact if it is not present, no
> further configuration needed.
>
> E.g. let's say you have one project that names 2 other projects A and B as
> submodules, and A depends on B. If you run `mvn install -pl A` (NOT SURE
> about that syntax), then Maven will look for B.jar from your local repo,
> and resort to checking your remote repo (e.g. Maven Central) if it's not
> there. But if you omit the `-pl A` part, Maven will build B, then build A
> using B.jar.
>
> Essentially, the plugin I linked to determines the project list based on
> what has changed and what has not. Maven then decides whether to use
> B/target/B.jar, ~/.m2/repository/.../B.jar, or to look to Maven Central.
>
> HTH.
>
> On Tue, Feb 4, 2020 at 4:08 PM Anton Vodonosov <[email protected]> wrote:
>
>> 04.02.2020, 23:32, "Jason Young" <[email protected]>:
>> >
>> > Not what you're looking for, but maybe useful: We use one plugin that
>> will
>> > skip whole projects that have not changed WRT a given Git branch:
>> > https://github.com/vackosar/gitflow-incremental-builder. With careful
>> > configuration, this is an effective shortcut without sacrificing
>> > repeatability.
>>
>> How do you use it? I mean if you need to start full system,
>> (locally or deploying it to a qa server),
>> but the plugin has only built changed modules,
>> how do you download the rest?
>>
>> Do you use this plugin in CI?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>
> --
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]