How to consume a published OLP schema dependency? - maven

This question is a minimum reproducible example based on the tutorial Build a Batch Pipeline with Maven Archetypes (Scala), though we are unable to consume a schema artifact in a pipeline we are building for a customer.
We have a separate repository we want to publish (mvn deploy) the schema from. We ran setup equivalent to (replace djv with your own unique string):
$ mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo.archetypes \
-DarchetypeArtifactId=pom-root \
-DarchetypeVersion=1.1 \
-DgroupId=com.example.djv \
-DartifactId=nodecardinality \
-Dversion=1.0.0 \
-Dpackage=com.example.djv.nodecardinality
...
$ cd nodecardinality
$ mvn archetype:generate -DarchetypeGroupId=com.here.platform.schema \
-DarchetypeArtifactId=project_archetype \
-DarchetypeVersion=1.0.13 \
-DgroupId=com.example.djv.nodecardinality \
-DartifactId=schema \
-Dversion=1.0.0 \
-Dpackage=com.example.djv.nodecardinality.schema \
-DmajorVersion=1
...
$ cat << EOF > schema/proto/src/main/proto/com/example/djv/nodecardinality/schema/v1/schema.proto
syntax = "proto3";
>
> package com.example.djv.nodecardinality.schema.v1;
>
> message NodeCardinalityPartition {
> repeated NodeCardinality node_cardinality = 1;
> }
>
> message NodeCardinality {
> string id = 1;
> uint32 cardinality = 2;
> }
> EOF
$ # <edit schema/ds/pom.xml per the tutorial>
$ cd schema
$ mvn deploy
Primary symptom
In the OLP Portal, I can see my new schema in the list of Schemas. It explains that I can add a dependency on it like so:
<dependency>
<groupId>com.example.djv.nodecardinality</groupId>
<artifactId>schema_v1_scala_2.11</artifactId>
<version>1.0.0</version>
<type>jar</type>
</dependency>
However, I cannot download the artifact in the processor project:
$ cd processor
$ mvn install
...
[INFO] Building processor Direct1toN Batch Processor in Scala 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from HERE_PLATFORM_REPO: https://repo.platform.here.com/artifactory/open-location-platform/com/example/djv/nodecardinality/1.0.0/nodecardinality-1.0.0.pom
Downloading from OLP Public repo: https://artifactory.in.here.com/artifactory/here-olp-sit/com/example/djv/nodecardinality/1.0.0/nodecardinality-1.0.0.pom
Downloading from central: https://repo.maven.apache.org/maven2/com/example/djv/nodecardinality/1.0.0/nodecardinality-1.0.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
...
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project processor: Could not resolve dependencies for project com.example.nodecardinality:processor:jar:1.0.0: Failed to collect dependencies at com.example.djv.nodecardinality:schema_v1_scala_2.11:jar:1.0.0: Failed to read artifact descriptor for com.example.djv.nodecardinality:schema_v1_scala_2.11:jar:1.0.0: Could not transfer artifact com.example.djv:nodecardinality:pom:1.0.0 from/to HERE_PLATFORM_ARTIFACT (here+artifact-service://artifact-service): Cannot access here+artifact-service://artifact-service with type here using the available connector factories: BasicRepositoryConnectorFactory: Cannot access here+artifact-service://artifact-service with type here using the available layout factories: Maven2RepositoryLayoutFactory: Unsupported repository layout here -> [Help 1]
...
We see this failure only because we are running the processor project build on the same machine that we ran mvn deploy for the schema project so some files exists in the ~/.m2 cache. Without these files the download just fails:
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from HERE_PLATFORM_REPO: https://repo.platform.here.com/artifactory/open-location-platform/com/example/djv/nodecardinality/schema_v1_scala_2.11/1.0.0/schema_v1_scala_2.11-1.0.0.pom
Downloading from OLP Public repo: https://artifactory.in.here.com/artifactory/here-olp-sit/com/example/djv/nodecardinality/schema_v1_scala_2.11/1.0.0/schema_v1_scala_2.11-1.0.0.pom
Downloading from central: https://repo.maven.apache.org/maven2/com/example/djv/nodecardinality/schema_v1_scala_2.11/1.0.0/schema_v1_scala_2.11-1.0.0.pom
[WARNING] The POM for com.example.djv.nodecardinality:schema_v1_scala_2.11:jar:1.0.0 is missing, no dependency information available
Downloading from HERE_PLATFORM_REPO: https://repo.platform.here.com/artifactory/open-location-platform/com/example/djv/nodecardinality/schema_v1_scala_2.11/1.0.0/schema_v1_scala_2.11-1.0.0.jar
Downloading from OLP Public repo: https://artifactory.in.here.com/artifactory/here-olp-sit/com/example/djv/nodecardinality/schema_v1_scala_2.11/1.0.0/schema_v1_scala_2.11-1.0.0.jar
Downloading from central: https://repo.maven.apache.org/maven2/com/example/djv/nodecardinality/schema_v1_scala_2.11/1.0.0/schema_v1_scala_2.11-1.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
...
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project processor: Could not resolve dependencies for project com.example.nodecardinality:processor:jar:1.0.0: Could not find artifact com.example.djv.nodecardinality:schema_v1_scala_2.11:jar:1.0.0 in HERE_PLATFORM_REPO (https://repo.platform.here.com/artifactory/open-location-platform/) -> [Help 1]
Secondary symptom
As we saw above, running mvn deploy from a local schema directory doesn't put everything required to build in the local ~/.m2 repository (that is, to build the processor sub-project). To put the required files in the local ~/.m2 repository we need to run mvn install from the parent directory (nodecardinality) of the schema repository.
This allows us to at least develop locally (temporarily).
Partial resolution
Follow the instructions in the section Artifact Service on the page Dependency Management ยท OLP SDK. Although the build gets farther, it still isn't able to pull the dependency:
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from HERE_PLATFORM_REPO: https://repo.platform.here.com/artifactory/open-location-platform/com/example/djv/nodecardinality/schema_v1_scala_2.11/1.0.0/schema_v1_scala_2.11-1.0.0.pom
Downloading from OLP Public repo: https://artifactory.in.here.com/artifactory/here-olp-sit/com/example/djv/nodecardinality/schema_v1_scala_2.11/1.0.0/schema_v1_scala_2.11-1.0.0.pom
Downloading from HERE_PLATFORM_ARTIFACT: here+artifact-service://artifact-service/com.example.djv.nodecardinality/schema_v1_scala_2.11/1.0.0/schema_v1_scala_2.11-1.0.0.pom
Downloaded from HERE_PLATFORM_ARTIFACT: here+artifact-service://artifact-service/com.example.djv.nodecardinality/schema_v1_scala_2.11/1.0.0/schema_v1_scala_2.11-1.0.0.pom (3.4 kB at 1.6 kB/s)
Downloading from HERE_PLATFORM_REPO: https://repo.platform.here.com/artifactory/open-location-platform/com/example/djv/nodecardinality/schema_v1/1.0.0/schema_v1-1.0.0.pom
Downloading from OLP Public repo: https://artifactory.in.here.com/artifactory/here-olp-sit/com/example/djv/nodecardinality/schema_v1/1.0.0/schema_v1-1.0.0.pom
Downloading from HERE_PLATFORM_ARTIFACT: here+artifact-service://artifact-service/com.example.djv.nodecardinality/schema_v1/1.0.0/schema_v1-1.0.0.pom
Downloaded from HERE_PLATFORM_ARTIFACT: here+artifact-service://artifact-service/com.example.djv.nodecardinality/schema_v1/1.0.0/schema_v1-1.0.0.pom (8.0 kB at 6.3 kB/s)
Downloading from HERE_PLATFORM_REPO: https://repo.platform.here.com/artifactory/open-location-platform/com/example/djv/nodecardinality/1.0.0/nodecardinality-1.0.0.pom
Downloading from OLP Public repo: https://artifactory.in.here.com/artifactory/here-olp-sit/com/example/djv/nodecardinality/1.0.0/nodecardinality-1.0.0.pom
Downloading from HERE_PLATFORM_ARTIFACT: here+artifact-service://artifact-service/com.example.djv/nodecardinality/1.0.0/nodecardinality-1.0.0.pom
Downloading from central: https://repo.maven.apache.org/maven2/com/example/djv/nodecardinality/1.0.0/nodecardinality-1.0.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
...
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project processor: Could not resolve dependencies for project com.example.nodecardinality:processor:jar:1.0.0: Failed to collect dependencies at com.example.djv.nodecardinality:schema_v1_scala_2.11:jar:1.0.0: Failed to read artifact descriptor for com.example.djv.nodecardinality:schema_v1_scala_2.11:jar:1.0.0: Could not find artifact com.example.djv:nodecardinality:pom:1.0.0 in HERE_PLATFORM_REPO (https://repo.platform.here.com/artifactory/open-location-platform/) -> [Help 1]

OLP Schemas are deployed to HERE Artifact Service. The service requires special authorization. In order to download a schema or java/scala binding you should include Maven Wagon in your project. Please refer to "Artifact Service" section in https://developer.here.com/olp/documentation/sdk-developer-guide/dev_guide/topics/dependency-management.html
In short:
Add version of the wagon as a property:
<artifact.wagon.version>1.6.1</artifact.wagon.version>
Add a placeholder repository to the list of repositories:
<repositories>
<repository>
<id>HERE_PLATFORM_ARTIFACT</id>
<layout>default</layout>
<url>here+artifact-service://artifact-service</url>
</repository>
</repositories>
Put the plugin reference in build section:
<extensions>
<extension>
<groupId>com.here.platform.artifact</groupId>
<artifactId>artifact-wagon</artifactId>
<version>${artifact.wagon.version}</version>
</extension>
</extensions>
Note that your need valid 'credentials.properties' file saved in ~/.here directory. How to get it please read https://developer.here.com/olp/documentation/sdk-developer-guide/dev_guide/topics/get-credentials.html
Best regards,
Dima

The issue is deployment with a parent Maven project. See the last sentence of the last error in the question:
Could not find artifact com.example.djv:nodecardinality:pom:1.0.0 in HERE_PLATFORM_REPO
The com.example.djv:nodecardinality:pom:1.0.0 POM was never uploaded when we ran mvn deploy from the schema directory. You cannot run mvn deploy from the top-level nodecardinality directory.
The simple solution is to remove the parent project pointer from the pom.xml in the schema directory before you run mvn deploy:
<!-- <parent>
<artifactId>nodecardinality</artifactId>
<groupId>com.example.djv</groupId>
<version>1.0.0</version>
</parent> -->

Related

GCLOUD Artifact Registry: Permissions error downloading maven dependency uploaded manually with Cloud Build

I have uploaded manually an maven dependency to my artifact repository
From my local PC, "mvn install" download correctly every maven dependency from the artifact repository, included my manually uploaded dependency.
mvn -U clean install -DskipTests=true
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.healthcentrix.prevvy:frontend >------------------
[INFO] Building frontend 2.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from cloud-artifacts: artifactregistry://us-central1-maven.pkg.dev/prevvy1/artifacts/org/moxieapps/gwt/highcharts/1.7.2/highcharts-1.7.2.pom
Downloaded from cloud-artifacts: artifactregistry://us-central1-maven.pkg.dev/prevvy1/artifacts/org/moxieapps/gwt/highcharts/1.7.2/highcharts-1.7.2.pom (401 B at 90 B/s)
Downloading from cloud-artifacts: artifactregistry://us-central1-maven.pkg.dev/prevvy1/artifacts/org/moxieapps/gwt/highcharts/1.7.2/highcharts-1.7.2.jar
Downloaded from cloud-artifacts: artifactregistry://us-central1-maven.pkg.dev/prevvy1/artifacts/org/moxieapps/gwt/highcharts/1.7.2/highcharts-1.7.2.jar (521 kB at 376 kB/s)
From Cloud Build or cloud-build-local, we got an permission error
[ERROR] Failed to execute goal on project frontend: Could not resolve dependencies for project com.healthcentrix.prevvy:frontend:jar:2.1-SNAPSHOT:
Failed to collect dependencies at org.moxieapps.gwt:highcharts:jar:1.7.2:
Failed to read artifact descriptor for org.moxieapps.gwt:highcharts:jar:1.7.2:
Could not transfer artifact org.moxieapps.gwt:highcharts:pom:1.7.2 from/to cloud-artifacts (artifactregistry://us-central1-maven.pkg.dev/prevvy1/artifacts):
Permission denied on remote repository (or it may not exist).
The request had no credentials because none were available from the environment.
Ensure that either 1) You are logged into gcloud or 2) Application default credentials are setup (see https://developers.google.com/accounts/docs/application-default-credentials for more information). 403 Forbidden
Step #0: [builder] [ERROR] {"error":"Permission "artifactregistry.repositories.downloadArtifacts" denied on resource "projects/prevvy1/locations/us-central1/repositories/artifacts" (or it may not exist)"}
Our Cloud build Project service account has every Artifact Registry permission, and is downloading the rest of depedencies excluding this specific artifact, which was uploaded manually
is necessary to give some specific permissions to this specific artifact? how?
Thanks in advance for any guidance
Regards

Caching Maven with Docker and Kotlin

I am trying to warm up my Docker + Maven cache before building a Kotlin project.
As suggested by many Maven/Docker threads, my docker file looks like this:
COPY pom.xml .
RUN mvn dependency:go-offline
COPY ./src/ src/
RUN mvn package
The thought is that if I change a file in the ./src directory, I want docker cache to skip maven's lengthy dependency download page.
My problem is that the mvn package command still downloads alot of files.
I tried to use mvn -o package (maven offline flag) to diagnose what dependencies are missing, but it just complains that it cannot download dependencies. But I would have expected that the dependencies would allready be downloaded in the previous step. Here are the errors that I get with the "-o" flag:
Step 8/13 : RUN mvn dependency:go-offline
---> Using cache
---> 0334facb9cc9
Step 9/13 : COPY ./src/ src/
---> Using cache
---> 27149a191017
Step 10/13 : RUN mvn -o package
---> Running in 5183eced32ca
Warning: JAVA_HOME environment variable is not set.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building auth 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # auth ---
[WARNING] The POM for org.apache.maven:maven-core:jar:2.0.6 is missing, no dependency information available
[WARNING] The POM for org.apache.maven:maven-monitor:jar:2.0.6 is missing, no dependency information available
[WARNING] The POM for org.codehaus.plexus:plexus-utils:jar:2.0.5 is missing, no dependency information available
[WARNING] The POM for org.apache.maven.shared:maven-filtering:jar:1.1 is missing, no dependency information available
[WARNING] The POM for org.codehaus.plexus:plexus-interpolation:jar:1.13 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.882 s
[INFO] Finished at: 2019-07-12T07:02:23+00:00
[INFO] Final Memory: 13M/174M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources (default-resources) on project auth: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources failed: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.apache.maven:maven-plugin-api:jar:2.0.6, org.apache.maven:maven-project:jar:2.0.6, org.apache.maven:maven-profile:jar:2.0.6, org.apache.maven:maven-artifact-manager:jar:2.0.6, org.apache.maven:maven-repository-metadata:jar:2.0.6, org.apache.maven:maven-plugin-registry:jar:2.0.6, org.apache.maven:maven-core:jar:2.0.6, org.apache.maven:maven-artifact:jar:2.0.6, org.apache.maven:maven-settings:jar:2.0.6, org.apache.maven:maven-model:jar:2.0.6, org.apache.maven:maven-monitor:jar:2.0.6, classworlds:classworlds:jar:1.1-alpha-2, org.codehaus.plexus:plexus-utils:jar:2.0.5, org.apache.maven.shared:maven-filtering:jar:1.1, org.codehaus.plexus:plexus-interpolation:jar:1.13: Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact org.apache.maven:maven-plugin-api:jar:2.0.6 has not been downloaded from it before. -> [Help 1
Try following mvn commands, it saved me from the maven error.
RUN mvn --batch-mode --errors --strict-checksums --threads 1C \
org.apache.maven.plugins:maven-dependency-plugin:3.0.2:go-offline
RUN mvn --batch-mode --errors --offline package
From what I gathered from various sources go-offline not always handles caching packages in a correct way, leaving some of them outside of the local repository (see pull request on GitHub).
In my case, the standard mvn dependency:go-offline used go-offline 2.8 and returned errors. I then tried running mvn org.apache.maven.plugins:maven-dependency-plugin:3.2.0:go-offline but I still had some issues with different packages.
What worked for me was using a different "go-offline" plugin available at GitHub.
Using
mvn de.qaware.maven:go-offline-maven-plugin:resolve-dependencies
finally did the job.

How to convert jars to dependencies and deploy them to a local repository?

My question is about mavenization, well the pupose is how to convert jars to dependencies from jsp servlet project to maven, i have succeeded to convert the project to maven with pom.xml file,
pom.xml generated:
<project.....>
<groupId>Calender</groupId>
<artifactId>Calender</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
Then i have opened the terminal and tried to this command and it get build success just below the command maven install:
mvn install:install-file -Dfile=target\Calender-1.0-SNAPSHOT.jar -DpomFile=pom.xml -Dsources=target\Calender-1.0-SNAPSHOT.jar
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) # Calender ---
[INFO] Installing D:\Calender\target\Calender-1.0-SNAPSHOT.jar to C:\Users\h.khadhri\.m2\repository\Calender\Calender\2.0\Calender-2.0.jar
[INFO] Installing D:\Calender\pom.xml to C:\Users\h.khadhri\.m2\repository\Calender\Calender\2.0\Calender-2.0.pom
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------
in my project i have external jars should i convert them to dependency ?
are the jars you have currently in your project on the global nexus repository? if so simply add a section to your pom file.
maven dependency documentation

maven plugin sonarqube doesn't resolve it's dependencies

When I try to run the mvn sonar:sonar target maven are unable to run sonar, here is the relevant part of the mvn output:
[INFO] Execute: org.codehaus.sonar:sonar-maven-plugin:3.6:sonar
[WARNING] While downloading javax.xml:jaxrpc:1.1
This artifact has been relocated to javax.xml:jaxrpc-api:1.1.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Can not execute Sonar
Embedded error: Unable to load the mojo 'org.codehaus.sonar:sonar-maven-plugin:3.6:sonar' in the plugin 'org.codehaus.sonar:sonar-maven-plugin'. A required class is missing: Lorg/apache/maven/shared/dependency/tree/DependencyTreeBuilder;
org.apache.maven.shared.dependency.tree.DependencyTreeBuilder
It seems like maven doesn't download the required dependency for some reason.
I have a local nexus configured that contains the jar, but i get the same result regardless if I have that profile active in my settings.xml or not.
How should I configure maven in order for it to try to download the dependency?
This was resolved by running:
mvn sonar:sonar -U
Apparently there was some corruption in the .m2 directory.

Does maven need Internet connection?

I try to build a project by maven.I tried
$ mvn archetype:generate -DgroupId=org.thoughtworks.app -DartifactId=mvntest -DarchetypeArtifactId=maven-archetype-quickstart
It worked.And then I tried
$ mvn archetype:generate -DgroupId=org.thoughtworks.app -DartifactId=mvntest
I mean,I delete archetypeArtifactId parameter.It fail,I didn't supply it with Internet.the error message is here.Is this parameter made it need Internet?Forget about other depedency.
[INFO] artifact org.apache.maven.archetypes:maven-archetype-quickstart: checking for updates from central
[WARNING] repository metadata for: 'artifact org.apache.maven.archetypes:maven-archetype-quickstart' could not be retrieved from repository: central due to an error: Error transferring file: repo1.maven.org
[INFO] Repository 'central' will be blacklisted
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] The desired archetype does not exist (org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE)
After you have all the dependencies downloaded on your local repository, then you can run mvn command with -o (offline) option and it should work, unless you don't need any other dependency from the remote repository (when the internet connection is needed).
If you have a repository with all the dependencies needed in your network you can reach on without the outside internet connection, just edit your settings.xml for your intranet dependencies.

Resources