Reputation: 130
I'm attempting a gitlab-ci build on a project with:
maven.repo.url
property set in settings.xmlThis works with a pom.xml when replacing the repositories.repository.url
entry from ${maven.repo.url}/public
to a hardcoded url, e.g. http://localhost:8081/nexus/content/repositories/public
. However, when attempting to use a property set in settings.xml, the build errors complaining that
Could not transfer artifact mygroup:myparent:1.0-SNAPSHOT from/to myrepo (${maven.repo.url}/public).
.gitlab-ci.yml
image: maven:3.6.1-jdk-8-alpine
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
paths:
- .m2/repository/
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS clean compile
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test
deploy:
stage: deploy
script:
- mvn $MAVEN_CLI_OPTS deploy
only:
- master
.m2/settings.xml (NOTE: I have MAVEN_REPO_URL
set in my GitLab Group variables)
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0
https://maven.apache.org/xsd/settings-1.1.0.xsd">
<!-- servers -->
<!-- mirrors -->
<profiles>
<profile>
<id>myprofile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<maven.repo.url>${env.MAVEN_REPO_URL}</maven.repo.url>
</properties>
</profile>
</profiles>
</settings>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>mygroup</groupId>
<artifactId>myparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>myartifact</artifactId>
<name>myname</name>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>mynexus</id>
<name>nexus repository</name>
<url>${maven.repo.url}/public</url>
</repository>
</repositories>
<!-- build, etc. -->
</project>
I'm expecting that I should be able to use the maven.repo.url
property in my pom.xml just like I use it every where else in my pom.xml. It works just fine for pulling down dependencies, it just cannot pull down my parent pom from a remote nexus repository.
Here is the maven error message:
$ mvn $MAVEN_CLI_OPTS clean compile
[INFO] Scanning for projects...
[WARNING] Could not transfer metadata mygroup:myparent:1.0-SNAPSHOT/maven-metadata.xml from/to myrepo (${maven.repo.url}/public): Cannot access ${maven.repo.url}/public with type default using the available connector factories: BasicRepositoryConnectorFactory
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for mygroup:myartifact:1.0-SNAPSHOT: Could not transfer artifact mygroup:myparent:pom:1.0-SNAPSHOT from/to myrepo (${maven.repo.url}/public): Cannot access ${maven.repo.url}/public with type default using the available connector factories: BasicRepositoryConnectorFactory and 'parent.relativePath' points at wrong local POM @ line 3, column 10
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project mygroup:myartifact:1.0-SNAPSHOT (/builds/gitlab/group1/myartifact/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for mygroup:myparent:1.0-SNAPSHOT: Could not transfer artifact mygroup:myparent:1.0-SNAPSHOT from/to myrepo (${maven.repo.url}/public): Cannot access ${maven.repo.url}/public with type default using the available connector factories: BasicRepositoryConnectorFactory and 'parent.relativePath' points at wrong local POM @ line 3, column 10: Cannot access ${maven.repo.url}/public using the registered transporter factories: WagonTransporterFactory: Unsupported transport protocol -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
ERROR: Job failed: exit code 1
Upvotes: 1
Views: 3393
Reputation: 130
I found that I needed to enable the snapshots repository for it to download the parent pom snapshot. Here is the updated .m2/settings.xml:
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0
https://maven.apache.org/xsd/settings-1.1.0.xsd">
<!-- servers -->
<!-- mirrors -->
<profiles>
<profile>
<id>myprofile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<maven.repo.url>${env.MAVEN_REPO_URL}</maven.repo.url>
</properties>
<repositories>
<repository>
<id>myrepo</id>
<url>${env.MAVEN_REPO_URL}/public</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
What is odd is that the Apache Maven settings documentation states that snapshots are enabled by default.
Came across this post that pointed me in the right direction.
Upvotes: 1