Consider I have a maven plugin project and I want to publish it to Github's public maven repository called "Github Packages". I've done everything by instruction and for normal projects everything works fine out of the box. But for maven plugin projects with packaging=maven-plugin the instruction doesn't work.
In build log I see something like this:
[WARNING] Could not transfer metadata repo-name/maven-metadata.xml
from/to github (https://maven.pkg.github.com/user-name/repo-name):
Failed to transfer file:
https://maven.pkg.github.com/user-name/repo-name/group-id/maven-metadata.xml.
Return code is: 422 , ReasonPhrase:Unprocessable Entity.
It seems the maven deploy plugin needs maven-metadata.xml in the group-id's root, but can't find it and no one puts it there. How to solve this problem?
I use Apache Maven 3.3.9, and use the command:
mvn clean deploy
--Addition: example of pom file I'm using:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>github</id>
<name>GitHub my_repo Apache Maven Packages</name>
<url>https://maven.pkg.github.com/my_nick/my_repo</url>
</repository>
</repositories>
<version>1.0.0</version>
<groupId>x</groupId>
<artifactId>some-plugin</artifactId>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>x</groupId>
<artifactId>my-dependency</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.github.javaparser</groupId>
<artifactId>javaparser-core</artifactId>
<version>3.15.12</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.6.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
</plugin>
</plugins>
</build>
</project>
Unfortunately I haven't found the right answer to my question, it seems that for now it's impossible to add Maven plugins to Github Packages.
However I found a workaround which uses S3 as a repository backend, so you don't need heavyweight solutions like Nexus or JFrog. You can read this and this on how to do it.
I had the same problem 422 from server: Unprocessable Entity when publishing Maven artifacts from GitHub Actions to GitHub Packages. The reason was that the corresponding tag for the uploaded artifact didn't exist yet.
The error message may be better in this case.
If you have already uploaded the artifact to the GitHub Packages then it means you have configured everything right.
I suppose the real reason for the 422 error is that you are trying to upload the same artifact with the same version that already was uploaded. And if it is not a SNAPSHOT version then the repository should deny replacing it so it behaves correctly.
I got the same error when trying to redeploy the already deployed package:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project MavenPluginForGithub:
Failed to deploy artifacts: Could not transfer artifact ru.dmochalov:SampleMavenPluginForGithub:jar:1.0.3 from/to github (https://maven.pkg.github.com/dmochalov/hello-world):
Failed to transfer file: https://maven.pkg.github.com/dmochalov/hello-world/ru/dmochalov/SampleMavenPluginForGithub/1.0.3/SampleMavenPluginForGithub-1.0.3.jar.
Return code is: 422, ReasonPhrase: Unprocessable Entity. -> [Help 1]
How to fix?
Is suppose you have two options:
Increment the version <version>1.0.0</version> of the plugin from 1.0.0 to 1.0.1. Consider using 1.0.1-SNAPSHOT versions if the plugin is unstable and under development. GitHub allows redeploying artifacts with SNAPSHOT versions. So you could always redeploy it when developing.
Delete the package from the repo. You can do it only for packages in a private repository.
422 error vs 401 error
I suppose that there is not accepted specification or standardization for error codes and different repositories behave differently. For example, the Maven Central repository replies with 401 error when attempting to replace the already deployed version.
Why GitHub decided to use 422 is a mystery. There is an answer in the community forum but without proper explanation.
Here's the official github link for how to do exactly that. However, since this doesn't seem to be of much help, here's a link to a gradle forum question that should help you with this. Best of luck!
Related
I'm following the "R for Data Science" tutorial for using the tidyverse. Because I'm eventually going to create a data analysis program in Java using Renjin, I need to be able to use the tidyverse's packages in my Maven project in Eclipse.
I've added the following dependencies in pom.xml:
<dependencies>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>renjin-script-engine</artifactId>
<version>3.5-beta76</version>
</dependency>
<dependency>
<groupId>org.renjin.cran</groupId>
<artifactId>tidyverse</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
I'm positive that the first dependency (renjin-script-engine) works. And I'm pretty sure the second dependency works as well. But whenever I run pom.xml and use the Maven test feature, it gives me the following error (I shortened it to just the important part):
[ERROR] Failed to execute goal on project Test1: Could not resolve dependencies for project Tests:Test1:jar:0.0.1-SNAPSHOT: org.renjin.cran:tidyverse:jar:1.3.2 was not found in https://nexus.bedatadriven.com/content/groups/public/ during a previous attempt.
I'm assuming that this error means I need another repository for tidyverse. Here is my current repository, which I got from the Renjin instructions:
<repositories>
<repository>
<id>bedatadriven</id>
<name>bedatadriven public repo</name>
<url>https://nexus.bedatadriven.com/content/groups/public/</url>
</repository>
</repositories>
(here's the link to those instructions as well: http://docs.renjin.org/en/latest/library/project-setup.html#maven)
I am not sure what repository I need to add.
Thank you for reading. I am a beginner, and I really appreciate any and all help.
I would like to add the following jar
gson-extras-1.0-SNAPSHOT.jar
the jar structure is the following
looking at the manifest the version is
Manifest-Version: 1.0
the pom is the following
<repositories>
<repository>
<id>grupoicarep</id>
<url>file:///C:/stix/stix_ica/stix2/lib/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.google.gson</groupId>
<artifactId>typeadapters</artifactId>
<version>0.1</version>
</dependency>
but it shows the following error:
Failed to execute goal on project stix2: Could not resolve dependencies for project es.grupoica:stix2:jar:0.0.1-SNAPSHOT: Failure to find com.google.gson:typeadapters:jar:0.1 in file:///C:/stix/stix_ica/stix2/lib/ was cached in the local repository, resolution will not be reattempted until the update interval of grupoicarep has elapsed or updates are forced -> [Help 1]
[ERROR]
I have tried many combinations but I am just guessing and not getting the right result
I donĀ“t know what I am doing wrong
many thanks in advance
Ana
Use below dependency to include the jar available in the local machine to maven.
<dependency>
<groupId>groupid</groupId>
<artifactId>artifactid</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}\lib\JAR_NAME.jar</systemPath>
</dependency>
I want to use a package named sourcemap in my project. It's not available in maven central, but in Atlassian's public maven repository. I therefore set up my pom.xml like this:
<repositories>
<repository>
<id>atlassian</id>
<name>Atlassian</name>
<url>https://packages.atlassian.com/content/repositories/atlassian-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.atlassian.sourcemap</groupId>
<artifactId>sourcemap</artifactId>
<version>1.7.7</version>
</dependency>
</dependencies>
Now, the POM file for sourcemap references another POM file from a package named public-pom:
<!-- POM for sourcemap (NOT my pom.xml!) -->
<parent>
<groupId>com.atlassian.pom</groupId>
<artifactId>public-pom</artifactId>
<version>3.0.84</version>
</parent>
The problem: the POM file references version 3.0.84 of public-pom, but Atlassian's repo no longer provides 3.0.84. Currently, the oldest available version of public-pom is 5.0.0, as you can see here. Because of this, maven complains when I attempt to build the project:
Could not find artifact com.atlassian.pom:public-pom:pom:3.0.84 in atlassian (https://packages.atlassian.com/content/repositories/atlassian-public/)
How can I fix the POM and use this package in my project?
Mvnrepository lists com.atlassian.pom:public-pom:pom:3.0.84 but when selecting the link to it:
status: 404
message: "Could not find resource"
Given the following modules in my pom.xml
<modules>
<module>core</module>
<module>middle-layer</module>
<module>top-layer</module>
<modules>
Where top-layer depends on middle-layer which depends on core.
When I run clean install it will build and install core and middle-layer successfully, but not top-layer. It tries to download middle-layer from a remote repository instead of using the freshly built one in the local repository.
I do have a custom remote repository specified in my pom.xml:
<repositories>
<repository>
<id>custom</id>
<url>http://someaddress/maven2/</url>
<snapshots>
<updatePolicy>never</updatePolicy>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</repository>
</repositories>
Why does it want to grab middle-layer from the remote repository?
Currently, everything is in SNAPSHOT-mode.
Middle layer dependency:
<dependencies>
<dependency>
<groupId>mygroup</groupId>
<artifactId>core</artifactId>
<version>2.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
Top layer dependency:
<dependencies>
<dependency>
<groupId>mygroup</groupId>
<artifactId>middle-layer</artifactId>
<version>2.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
They all inherent their versions from the parent (currently at 2.0.1-SNAPSHOT) and I'm calling install from the parent pom.
Maven frequently prints messages about downloading things that it is not, in fact, downloading. It is considering the possibility that there is a newer snapshot available remotely than the last one build locally. This is why uploading snapshots is often a really bad idea.
I found the answer.
It was a typical problem between keyboard and chair.
The middle-layer is actually historically a WAR, not a JAR, that is to say: it includes some classes I needed in my top-layer. (It's not really called middle-layer of course).
So top-layer searches for middle-layer.jar and can't find it (because it's a WAR).
So I have to refactor some stuff to get the things I need from middle-layer into a new library JAR and make both middle-layer and top-layer depend on that instead.
Sorry to waste your time. :)
I'm using Maven for the first time. I am trying to build "GeoTools" (http://www.geotools.org/) which has a seemingly well documented "Getting Started" page. I am using NetBeans 7.3.1. When I build my project, I get a "Build Failure" :
Failed to execute goal on project tutorial: Could not resolve dependencies for project org.geotools:tutorial:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: org.geotools:gt-shapefile:jar:10-SNAPSHOT, org.geotools:gt-swing:jar:10-SNAPSHOT: Failure to find org.geotools:gt-shapefile:jar:10-SNAPSHOT in http://download.java.net/maven/2 was cached in the local repository, resolution will not be reattempted until the update interval of maven2-repository.dev.java.net has elapsed or updates are forced -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
I'm not really sure what that means. In my code I have several imports that are considered to not exist, though I followed the pom.xml instructions to the letter. For example:
import org.geotools.data.FileDataStore;
The above has a read underline with error saying:
package org.geotools.data does not exist
Here is my 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.geotools</groupId>
<artifactId>tutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>tutorial</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<geotools.version>10-SNAPSHOT</geotools.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-shapefile</artifactId>
<version>${geotools.version}</version>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-swing</artifactId>
<version>${geotools.version}</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
</repositories>
Can anyone give me some advice to get this tool running? Am I making a fundamental Maven error or could it be tool-specific? The JARs show up under "Dependencies" so I don't understand why there's a problem.
Thanks in advance.
The real answer is that the GeoTools tutorial is pernicious. So if any future stragglers come here know this: on the NetBeans tutorial (and perhaps the Eclipse tutorial which I also failed to get to work) there are steps which define how to set up the pom.xml. Follow them. However, do NOT copy and paste their full pom.xml file, there's an error in it somewhere. I merely added the dependencies and repositories and built the project - successfully.
But wait there's more. After building the project I was unable to run the Quickstart.java example they provide. It crashed because
JMapFrame.showMap(map)
only accepts a "MapContext" type, which the documentation calls "deprecated". So, I imported
org.geotools.map.MapContext
and changed
MapContent map = new MapContent();
to
MapContext map = new MapContext();
Viola, beating the system. I wish developers would actually test their tutorials!