Skip to content

ppalaga/srcdeps

 
 

Repository files navigation

Srcdeps

Build Status

A set of tools for building dependencies from their sources during the build.

What is this good for?

Srcdeps alleviates some of the pains that arise from implementing Continuous Delivery in Maven projects. With srcdeps, a module can depend on a specific revision of another module. For instance, a module web-banking-frontend could depend on account-balance-microservice at git revision abc123, without requiring the account-balance-microservice to perform a complete Maven release.

Srcdeps support for Maven

Currently, the srcdeps toolkit supports only Maven 3.3.1+, although the srcdeps-core library has an ambition to be generic enough so that a support for other Java build tools such as Gradle or sbt can be added (contributions are welcome!).

The present solution for Maven is leveraging the concept of Maven Core Extensions introduced in Maven 3.3.1. In particular, we provide an implementation of LocalRepositoryManager that delegates all the usual artifact lookup work to the standard local repository manager available in Maven class path, but it is watching carefully, if the requested artifact contains -SRC- in its version string. For such ones, the srcdeps-core library is called, to build what is necessary and install it to the Maven local repository. In other words, the dependencies are built and installed while they are looked up.

How to configure for Maven:

1. .mvn/extensions.xml

srcdeps-maven-local-repository needs to be declared as a Maven Core Extension in .mvn/extensions.xml of the maven project.

<?xml version="1.0" encoding="UTF-8"?>
<extensions>
  <extension>
    <groupId>org.l2x6.maven.srcdeps</groupId>
    <artifactId>srcdeps-maven-local-repository</artifactId>
    <version>1.0.1</version><!-- @srcdeps.version@ -->
  </extension>
</extensions>

2. .mvn/srcdeps.yaml

A few settings have to be configured in .mvn/srcdeps.yaml file. Especially, the mapping from groupId’s of dependencies to SCM repositiries where their sources reside. This is a minimal .mvn/srcdeps.yaml file. Please refer to srcdeps.yaml.adoc for full reference.

configModelVersion: 1.0
repositories:
  srcdepsItestRepo:
    selectors:
    - org.l2x6.maven.srcdeps.itest # if one of the selectors matches the groupId of a -SRC- dependency,
                                   # then the urls will be used to build that dependency
    urls:
    - https://github.com/srcdeps/srcdeps-test-artifact.git # If you list multiple SCM repos here
                                                        # then the first successful checkout will count

Examples a.k.a. Quickstarts

There is a couple of ready-to-build self-contained examples in the srcdeps-maven-quickstarts directory. Perhaps the most prominent of them is the srcdeps-mvn-git-revision-quickstart that demonstrates how a project can depend on a source revision of another project.

How Srcdeps tools work

  • Srcdeps tools are supposed to build dependencies with versions matching {whatever}-SRC-{srcVersionType}-{srcVersion}

  • Any artifact having such a -SRC- version that is requested during the build needs to have an associated SCM repository in the configuration. For Maven, the configuration is stored in .mvn/srcdeps.yaml under the top level directory of the project.

  • The URL of the associated SCM repository is used to fetch the sources of the dependency and checkout the desired revision. For Maven the sources are cloned to ${maven.repo.local}/../srcdeps/${scmRepo.id}

  • Then, srcdeps-core changes the version in the sources to {whatever}-SRC-{srcVersionType}-{srcVersion} using Versions Maven Plugin

  • And finally, srcdeps-core builds the artifacts and installs them to the local Maven repository

  • For Maven, the -SRC- dependencies are build only if they are not found in local repository - so they prolong the build only when upgrading.

Misc.

Legacy note

Originally, the present project provided a Maven plugin called srcdeps-maven-plugin that worked fairly well in most situations, but it turned out soon that the Maven Plugin API is not rich enough to allow for catching dependencies of all possible kinds. Most notably, the given project’s parent pom and imports in dependencyManagement sections were resolved by Maven even before the plugin was initialized. Thus, if the given project’s parent pom had a -SRC- version, the build failed with a missing artifact error message, simply because it happened before srcdeps-maven-plugin could do anything.

An outdated presentation about the abandoned srcdeps-maven-plugin: http://ppalaga.github.io/presentations/150929-srcdeps-maven-plugin/150929-srcdeps-maven-plugin.html

About

A Maven plugin that can compile and install current project's dependencies from their sources

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 94.3%
  • Shell 3.3%
  • Batchfile 2.4%