An organization produces a deliverable (a.k.a. main distro) using Java and Maven
Maven -SNAPSHOT
s
-SNAPSHOT
version of an artifact can change in the course of time-SNAPSHOT
s are non-reproducible in course of timeMaven timestamped SNAPSHOT
s
Release components often
We could build the components on the fly from their sources!
-SRC-
dependendciesA Maven plugin that allows a Maven Project A to depend on source revision, tag or branch of another project B.
<!-- In project A's pom.xml -->
<dependencies>
<dependency>
<groupId>org.example.b</groupId>
<artifactId>artifact-b</artifactId>
<version>0.0.1-SRC-revision-66ea95d8</version>(1)
</dependency>
</dependencies>
1 | -SRC- is the marker that makes Srcdeps Plugin to interpret the rest of the version string as a scmVersionType ,
scmVersion pair. In this case scmVersionType is revision and scmVersion is
66ea95d8 - i.e. the sha1 of the git commit we want to build as a dependency. |
<plugin>
<groupId>org.l2x6.maven.srcdeps</groupId>
<artifactId>srcdeps-maven-plugin</artifactId>
<version>0.0.4</version>
<extensions>true</extensions>(3)
<configuration>
<repositories>
<repository>
<id>group-b</id>(4)
<selectors>
<selector>org.example.b</selector>(1)
</selectors>
<url>scm:git:https://github.com/example/project-b.git</url>(2)
</repository>
...
</repositories>
</configuration>
</plugin>
1 | This is how the plugin knows which SCM URL belongs to which artifact maked with -SRC- version. For now <selector>
is the groupId a source dependency |
2 | The SCM (Source Code Management) URL to checkout the sources from. |
3 | srcdeps-maven-plugin is a Maven extension rather than a usual Maven plugin because it needs to listen to basic Maven lifecycle events |
4 | An id that should map 1:1 to the URL |
The build of org.example.main-distro issued:
cd project-a; mvn clean install
afterProjectsRead()
listener method of srcdeps-maven-plugin is called very early in the Maven build process,
even before the dependencies of the project are resolved.-SRC-
-SRC-
dependency, find source repository in srcdeps-maven-plugin
's configurationFor each source repository:
~m2/../dependency-sources
-SRC-
in the version stringmvn versions:set -DnewVersion=0.0.1-SRC-revision-66ea95d8
mvn clean install
in the checkout directory-SRC-
dependencies are installed in the local Maven repository-SRC-
dependenciies were recently installed in the local Maven repository.SCM agnostic
scmVersionType
in -SRC-{scmVersionType}-{scmVersion}
can be anything the given SCM supports
* for most SCMs scmVersionType
: {revision|tag|branch}
srcdeps.quiet
use -q
for nested builds to reduce log length (sometimes important for Travis)
srcdeps.skipTests
, srcdeps.mavenTestSkip
to make the nested builds faster
A way how I can build the project A that has a -SRC-
dependency on project B on my machine even before the change
was accepted in the upstream of project A.
pom.xml
configuration, the fallback URLs are usedmvn clean install -Dsrcdeps.url.1.group-b=scm:git:file:///home/ppalaga/git/project-b/.git
Where:
1
is an index (1 is the lowest possible index)group-b
is the id
of the SCM repository URL from srcdeps-maven-plugin’s configuration that this fallback should apply to/