How to see what Maven is sending to a server during deploy?
Asked Answered
S

5

4

I'm trying to use Github's new Actions CI server to deploy packages to Github's new packages feature. It's not going well.

I think it's all set up correctly, but I get this error:

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy 
(default-deploy) on project myproject: Failed to deploy artifacts: Could not 
find artifact com.mycompany:myproject:pom:1.5 in github 
(https://maven.pkg.github.com/mycompany/mycompany_repository) -> [Help 1]

This happens after it appears to upload that same pom successfully:

Uploading to github: https://maven.pkg.github.com/mycompany/mycompany_repository
/com/mycompany/myproject/1.5/myproject-1.5.pom
Progress (1): myproject-1.5.pom (4.1/6.1 kB)
Progress (1): myproject-1.5.pom (6.1 kB)

So, it looks to me like it is successfully uploading the pom, but then it fails to download the same pom a few seconds later.

I'm running the deploy with debug switches on: mvn -X -e deploy, but I can't see the exact http commands that Maven is sending to the server.

How do I debug this? Is there some Maven/Aether transport or something that will log what is going on under the covers?

Sciatic answered 19/12, 2019 at 17:7 Comment(0)
R
4

In case anyone else lands here looking for a solution to OPs issue publishing to github, I had a similar issue and found that the URLs needed in settings.xml and pom.xml are inconsistent. In your settings.xml, the repo URL needs to be of the form https://maven.pkg.github.com/myuser/com/mycompany/mypackage, whereas in your project's pom file, it needs to be of the form https://maven.pkg.github.com/myuser/mypackage. So, for example, your settings.xml file in ~/.m2 would look something like this:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <activeProfiles>
    <activeProfile>github</activeProfile>
  </activeProfiles>

  <profiles>
    <profile>
      <id>github</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>false</enabled></snapshots>
        </repository>
        <repository>
          <id>github</id>
          <name>GitHub Apache Maven Packages</name>
          <url>https://maven.pkg.github.com/myuser/com/mycompany/mypackage</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>false</enabled></snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>myuser</username>
      <password>mypersonalaccesstoken</password>
    </server>
  </servers>
</settings>

Whereas the pom.xml file in the root of your project would need to look like this:

<project>
  ...
  <groupId>org.mycompany</groupId>
  <artifactId>mypackage</artifactId>
  <version>1.0.0</version>
  ...
  <distributionManagement>
    <repository>
      <id>github</id>
      <name>GitHub Apache Maven Packages</name>
      <url>https://maven.pkg.github.com/myuser/mypackage</url>
    </repository>
  </distributionManagement>
  ...
</project>

Other than this minor (but crucial) detail, my steps were the same as those outlined here. This allowed me to publish my Maven package to github package registry.

Reimport answered 21/2, 2020 at 6:28 Comment(6)
The settings.xml is shared between all the projects on your machine deployed by your user, so how could it have a url that is specific to a package from a specific project?Sky
It doesn't make sense that you would be expected to use your personal username in the file that would get checked in and re-used by all members of the team.Nitrile
@Nitrile Perhaps not, but the fact remains that it worked for me. Is your experience that software always works in a sensible manner?Reimport
@Jason - No, but Github obviously isn't expecting users working together as a team to tie a given project exclusively to their own private github account. I was eventually able to get this working with the org's name in every path so it does in fact work as expected/documented.Nitrile
@Jason - Thank you for this suggestion here. Do you know if a similar issue exists in Azure DevOps repositories also? I am facing this similar issue but the structure of the Settings file is different ie. does not use profiles. linkPoised
@Poised Maven and ADO are completely different animals and, as far as I know, no "Maven compatibility" layer exists on top of the ADO artifacts repo. I would try searching ADO-tagged questions for help with this.Reimport
K
2

You can enable debug logging in the workflows.

Just add the secret:

ACTIONS_RUNNER_DEBUG

And set to true

See a similar answer here

Katekatee answered 20/12, 2019 at 3:12 Comment(0)
S
1

I just spend 3 hours debugging why the guide on the page did not work for me. If you are following the guide posted here 1.

OWNER is your github username, and REPOSITORY is - you guessed it, the repo name.

Just remember to use lowercase in both OWNER and REPOSITORY.

Shaniqua answered 28/8, 2020 at 14:32 Comment(0)
S
0

The following solution works for me:

  1. Create a repository for packages e.g. maven-packages
  2. Add <server></server> settings under <servers> in settings.xml: (do this per id used below)
    <server>
        <id>github</id>
        <username>YOUR GITHUB USERNAME</username>
        <password>A GITHUB TOKEN YOU CREATE FOR PUBLISHING PACKAGES</password>
    </server>
  1. Do NOT add <activeProfiles>, <profile> or <repositories> to settings.xml (only add <server> elements) as this is redundant for publishing and I am adding them to consuming projects' maven.xml so no need for duplication.
  2. Add repository/ies to distributionManagement in pom.xml as follows:
    <distributionManagement>
        <snapshotRepository>
            <id>github-snapshot</id>
            <name>GitHub snapshot</name>
            <url>https://maven.pkg.github.com/OWNER/maven-packages/</url>
            <uniqueVersion>true</uniqueVersion>
        </snapshotRepository>
        <repository>
            <id>github-release</id>
            <name>GitHub release</name>
            <url>https://maven.pkg.github.com/OWNER/maven-packages/</url>
            <uniqueVersion>false</uniqueVersion>
        </repository>
    </distributionManagement>

Where OWNER is the GitHub account your project is / projects are under and maven-packages is the repositories you want to publish you project(s) to.

This enables using a dedicated repository for listing packages instead of publishing each project's package to a different (its own) repository, making consumption of multiple packages from your GitHub account easier, as you only need to configure a single repository for these packages:

    <repositories>
        <repository>
            <id>github</id>
            <name>GitHub</name>
            <url>https://maven.pkg.github.com/OWNER/maven-packages/</url>
        </repository>
    </repositories>

Note: in the <servers> section of your settings.xml define a <server> per id used in repositories and distributionManagement e.g. github-snapshot, github-release, github in the above examples.

Sky answered 25/2, 2020 at 16:17 Comment(0)
L
0

When generating the personal access token, make sure the scopes for the token are the repo:* scopes as well as the more obvious write:packages and read:packages scopes (do not disable the repo scopes)

Otherwise it does just that

Legalize answered 25/1, 2021 at 20:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.