I have a problem with GitHub packages and dependencies. I published SNAPSHOTs for few packages in GitHub packages, and I'm trying to use them when building artifacts but with no luck. I always get 401 unauthorized from Maven when trying to reach it. So, settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<localRepository>./mavenRepo</localRepository>
<interactiveMode>true</interactiveMode>
<offline>false</offline>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>github</id>
<username>ArturJarosz</username>
<password>MAVEN_GITHUB_TOKEN</password>
<configuration>
<httpHeaders>
<property>
<name>Authorization</name>
<value>Bearer MAVEN_GITHUB_TOKEN</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
<mirrors>
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
</mirrors>
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/ArturJarosz/Task</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>
</settings>
As you can see I have tried both ways of authorizing server that I have found. According to the documentation, username and password should be enough: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry
Also other people seems to be successful with that approach: How to access maven dependecy from GitHub Package Registry (Beta)
Header path was added after reading that one, I assumed it will not hurt: https://github.com/orgs/community/discussions/49836#discussioncomment-5413387
I replaced token here of course, but let's assume that is hardcoded here (I tried injecting from env as well). When I check that token with curl:
curl -sS -f -I -H "Authorization: token MAVEN_GITHUB_TOKEN" https://api.github.com | grep -i x-oauth-scopes
I get: delete:packages, write:packages And I assume that scope of the token is sufficient, as under write is read as well.
But when trying to resolve it using Maven:
#13 2.865 [DEBUG] Could not find metadata com.arturjarosz:task-parent:0.6.1-SNAPSHOT/maven-metadata.xml in local (/task-schema/./mavenRepo)
#13 3.302 [DEBUG] Using transporter HttpTransporter with priority 5.0 for https://maven.pkg.github.com/ArturJarosz/Task
#13 3.302 [DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://maven.pkg.github.com/ArturJarosz/Task with username=ArturJarosz, password=***
#13 3.306 Downloading from github: https://maven.pkg.github.com/ArturJarosz/Task/com/arturjarosz/task-parent/0.6.1-SNAPSHOT/maven-metadata.xml
#13 4.242 [DEBUG] Writing tracking file '/task-schema/./mavenRepo/com/arturjarosz/task-parent/0.6.1-SNAPSHOT/resolver-status.properties'
#13 4.254 [WARNING] Could not transfer metadata com.arturjarosz:task-parent:0.6.1-SNAPSHOT/maven-metadata.xml from/to github (https://maven.pkg.github.com/ArturJarosz/Task): status code: 401, reason phrase: Unauthorized (401)
#13 4.258 org.eclipse.aether.transfer.MetadataTransferException: Could not transfer metadata com.arturjarosz:task-parent:0.6.1-SNAPSHOT/maven-metadata.xml from/to github (https://maven.pkg.github.com/ArturJarosz/Task): status code: 401, reason phrase: Unauthorized (401)
I am able to download that POM/related JAR with curl by hand with that token. Do you have any idea what am I doing wrong? I will appreciate any help.
EDIT: Seems like I was wrong with token. Scope was not sufficient, and it required also metadata scope. With new token everything works as expected.