maven


How can I reference a local Mercurial repository in Maven if it is two directories up?


We have been using SCM URLs in POM files like this:
<scm>
<connection>scm:hg:file:///${basedir}</connection>
<developerConnection>scm:hg:file:///${basedir}</developerConnection>
</scm>
It requires us to start the release process with a "mvn release:prepare -DpushChanges=false", but we had to do that anyway (the hg plugin doesn't handle authentication correctly). The big plus for us is that we can "hg strip" if the release process goes wrong at any point -- no one but the local developers will ever see that.
The same process works if we have a directory inside a Mercurial checkout. In that case the following URLs do the trick:
<scm>
<connection>scm:hg:file:///${basedir}/..</connection>
<developerConnection>scm:hg:file:///${basedir}/..</developerConnection>
<tag>HEAD</tag>
</scm>
But: it all goes wrong when there's another level in there. I have tried a number of variations of the file URL, but they all seem to fail.
The naive approach of using "scm:hg:file:///${basedir}/../.." causes both the site plugin as well as the release plugin to fail. The former will tell me this:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.2:site (default-site) on project epik-protocol-spec: Execution default-site of goal org.apache.maven.plugins:maven-site-plugin:3.2:site failed: This SCM url 'scm:hg:file:///../epik-protocol-spec' is invalid due to the following errors:
[ERROR] * An hg 'file' url must be on the form 'file:///' or 'file://localhost/'.
[ERROR] For more information about SCM URL Format, please refer to: http://maven.apache.org/scm/scm-url-format.html
('epik-protocol-spec' is the name of a module in the build that is running)
The release plugin encounters a similar issue: after a release:prepare the release.properties file will have the scm.url set to "file:///..", which will then fail to get a copy of the tagged code during release:perform. The workaround for this is to fix the property manually between the steps. I haven't found a way to make the site build work, yet.
My goals are:
have a build that just works out of the box (i.e. clone the project from IDE and run any target)
be able to generate the site (and run other builds) on a build server
be able to run releases with the release plugin, with all changes being reviewed before pushing
Has anyone a solution for this? And why do the URLs get mangled so badly -- is the approach bad or are we encountering a Maven problem?
Edit
As proposed by Charlee, I checked the output of mvn help:effective-pom. The SCM URLs are mangled in that. It also shows that Maven appends module names to the URLs, which means it will be necessary to define the URLs on each module -- assuming that the odd mangling can be stopped.
A custom property like this:
<properties>
<test.property>scm:hg:file:///${basedir}/../..</test.property>
</properties>
does not get mangled, it gets resolved as expected (also checked using the effective POM).
The Maven SCM provider is shortening URLs based on a "../" and "..\" matching scheme. If one of these character sequences is matched, it will search backwards for a matching slash (past the one just prior), removing everything back to that. This rule meant that my file URLs, which would look something like this:
scm:hg:file:///C:\some\local\path/../..
would trigger the shortening due to the "../" sequence, it would then delete back to the previous forward slash, which means back to the slash before the "C:", thus deleting the whole path.
This behaviour is not triggered if there's no slash behind the dots, so the step up at the end of my URLs caused no harm -- which explains why I had no issues with going up one level.
The solution (workaround?) is to use this:
scm:hg:file:///${basedir}${file.separator}..${file.separator}..
Then the URL shortening will encounter matching slashes no matter the OS and it starts to work again.
Regarding to the SCM Implementation: Mercurial, it mentions at the example as the following: -
scm:hg:http://host/v3
scm:hg:file://C:/dev/project/v3 (windows drive)
<--- only 2 slashes + [os, e.g. drive:/path/...]
scm:hg:file:///home/smorgrav/dev/project/v3 (linux drive)
<--- only 2 slashes + [os, e.g. /home/...]
scm:hg:/home/smorgrav/dev/project/v3 (local directory)
Anyhow the Maven told us as
This SCM url 'scm:hg:file:///../epik-protocol-spec'
is invalid due to the following errors
Please correct me, if I'm wrong. I understand that you're in the Microsoft Windows environment and may use only 2 slashes for achieving your requirement.
Anyhow the another suspected may be the ${basedir} is resolved as ../epik-protocol-spec. If I understand correctly, it should be a full path instead.
I hope this may help.

Related Links

Maven, Ant (or Apache Thrift) times out during make. Where to place proxy settings?
How to set default values for missing environment variables in maven pom
failed to get report for ru.yandex.qatools.allure:allure-maven-plugin: Unable to load the mojo 'aggregate'
Is it possible to create a Maven archetype just for some packages?
Building/Packaging SOA using maven in Jenkins
Why are my webResources not packaged if I run mvn clean install?
Spring Boot Maven Plugin - Define working directory
Detach application from gitlab runner
Maven add my own information during build to MANIFEST.MF file
do not create meta-inf/maven in jar package when using maven assembly plugin
Elasticsearch Java API from web application-error: java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.threadpool.ThreadPool
OutOfMemoryError during test execution
How can I exclude exclude java files from cobertura report maven
Unable to retrieve EntityManagerFactory for unitName - JPA configs problems
Does Neo4j spatial server plugin 3.0.2 work with Neo4j 3.0.3 community?
Environment Variables required to setup maven?

Categories

HOME
yii2
listview
gerrit
minimum-spanning-tree
gremlin
deezer
kde
path-finding
cmd
youtube-api-v3
callback
pivotal-cloud-foundry
datastax-java-driver
constraint-programming
autotools
pheatmap
applepay
vifm
adobe-analytics
vault
commonmark
quickfix
saxon
footer
introduction
nas
wkwebview
claims-based-identity
rundeck
angular2-aot
qhull
pepper
underflow
url-scheme
wpfdatagrid
windows-error-reporting
log4js-node
kendo-datasource
google-cloud-nl
tinymce-4
iframe-resizer
fog
noraui
stringtemplate
bower-install
uft-api
temporary-files
ensembles
grid.mvc
btrace
logfiles
google-datalayer
menuitem
jsch
python-c-api
elgg
carrot
r-forge
spring-mongodb
gnome-shell-extensions
abcpdf9
gridpane
azure-sdk
file-writing
mikroc
measures
nsfilemanager
firebaseui
gstreamer-0.10
master-slave
bgp
rvest
dataview
nessus
ipconfig
iad
vhd
qtableview
t4mvc
collapse
qdialog
purge
operation
mmc
composite
key-management
graph-api-explorer
typekit
mdt
cctv
responsive-slides
contenttype
transcoding
mbr
dexterity
odata4j
back-stack
mylyn
xamlparseexception
android-screen-support
free-variable
anonymous-methods
bitsharp
coderush
multipage
ohm
boost-filesystem
fireworks
window-management
cinema-4d
html-input
coda-slider
wise
forums
perfect-hash
thunderbird-lightning
substrings
webkit.net
yagni
procedural-music
defensive-programming
msdev

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App