How to publish Maven artifacts in Jitpack with "Flavour" defined by Maven profile?

Asked

Viewed 26 times

1

I have a number of dependencies that I now need their normal "flavor", time I need their "flavor" without Amblas.

I’ll take care of it by profiling retrolambda enabled or not. One of my projects I need this is totalcross-functional-toolbox. Currently, what I have is a build on gitlab-CI to publish in a private artifact repository, but I’m thinking of switching to Jitpack. What I do is currently on .gitlab-ci.yml of the project:

archive-functional-toolbox:
  script:
    - ./mvnw $MAVEN_CLI_OPTS clean deploy -pl :totalcross-functional-toolbox,:totalcross-functional-toolbox-bom,:gwt-functional-toolbox-is-serializable -am
    - ./mvnw $MAVEN_CLI_OPTS clean deploy -pl :totalcross-functional-toolbox,:totalcross-functional-toolbox-bom -P retrolambda

Note how, to publish the two flavors, I have run clean deploy whether or not to enable the profile retrolambda. This difference in flavors I put in the version. A priori, the version is 2.0.1${revision}, if I don’t profile retrolambda turns out that ${revision} expands to empty string, with the profile expands to +retrolambda.

In this case, as the Jitpack controls the life cycle, is there any way I can detect which "Flavor" is being requested to build properly? I will now require the artifact com.gilab.geosales-open-source:totalcross-functional-toolbox:2.0.1, now the artifact com.gilab.geosales-open-source:totalcross-functional-toolbox:2.0.1+retrolambda, how to know which artifact I am requiring to correctly generate the desired version?

For now, ignoring the fact that the sample project is a multi-module Maven project, the answer can consider only as if it were a simple Maven project

1 answer

1


Jitpack allows you to place a custom build script. In this script, it guarantees some variables. In the case, the guaranteed variable VERSION brings the desired version to be generated. For example, if somewhere you have the dependency com.gitlab.geosales-open-source:totalcross-resultset-extractor:1.0.1-retrolambda, Jitpack will pass the variable VERSION=1.0.1-retrolambda for the script.

Then, in case the version passes some scheme of "flavor" to the generated artifact, it is necessary to do some processing in the variable VERSION past tense. For example:

./mvnw `[[ "$VERSION" == *-retrolambda ]] && echo "-P retrolambda"` clean install

This verifies whether the version satisfies the glob *-retrolambda; if satisfied, will perform the textual replacement for -P retrolambda, otherwise it will be replaced by the empty string. This way, it is possible to detect the desired "flavor" for the build and use a Maven profile associated with it.

It is worth mentioning that, in the tests, use + as part of the version string didn’t work out so well, either not properly recognizing the version string or saying it is "invalid version".

The Jitpack build file is identified by jitpack.yml at the root of the directory. More information on official documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.