Skip to content
\n

I also need to add maven repository into pom.xml.

\n
    <repository>\n      <id>github-me-my-repo</id>\n      <layout>default</layout>\n      <name>GitHub Packages Repo</name>\n      <releases><enabled>true</enabled></releases>\n      <snapshots><enabled>false</enabled></snapshots>\n      <url>https://maven.pkg.github.com/me/my-repo</url>\n    </repository>\n
\n

This does not work, because when maven attempt to download artifact it failes, because request is unauthorized.

\n

GitHub Packages help tells that I need to add my user name and token into settings.xml.

\n

This probably fixes an issue.
\nBut there is so much nonsense in this requirement.

\n

For example, if I clone some project which rely on dependencies hosted on GitHub Packages maven repo I’ll fail to compile it. Will have to investigate what the heck is going on. Figure out that I need to register on GitHub. Then generate token. Store in in ~/.m2/settings.xml. And only then the project might compile.

\n

On the other hand the dependency JAR could be downloaded manually via https://github.com/me/my-repo/packages, so why on earth authorization is required when downloaded via maven?

\n

Is there any hidden setting to turn off requirement?

","upvoteCount":117,"answerCount":47,"acceptedAnswer":{"@type":"Answer","text":"
\n

For example, if I clone some project which rely on dependencies hosted on GitHub Packages maven repo I’ll fail to compile it. Will have to investigate what the heck is going on. Figure out that I need to register on GitHub. Then generate token. Store in in ~/.m2/settings.xml . And only then the project might compile.

\n
\n

There are a few thing you can do to make this a little less painful.

\n
    \n
  1. Create a settings.xml file at the root of your repository
  2. \n
  3. Create a .mvn/maven.config file that contains -s settings.xml\n
  4. \n
  5. Generate a PAT with just the read:packages scope
  6. \n
\n

If your repository is private, you can place the PAT directly in your settings.xml file. If your repository is public, you can’t push the raw PAT to your repository because GitHub will automatically delete it. What you can do instead is store an XML encoded version of the PAT (to prevent automatic deletion).

\n

You can find an example of this here:
\n

\n \n

\n GitHub\n \n \n

\n

jcansdale-test/maven-consume

\n

An example Maven project that consumes a package. Contribute to jcansdale-test/maven-consume development by creating an account on GitHub.

\n \n
\n
\n
\n\n

You can now clone and compile like this:

\n
git clone https://github.com/jcansdale-test/maven-consume\ncd maven-consume\nmvn compile\n
\n

If you have Docker installed, you can generate an XML encoded PAT like by doing:

\n
docker run jcansdale/gpr encode TOKEN\n
\n

I hope that helps!

","upvoteCount":9,"url":"https://github.com/orgs/community/discussions/26634#discussioncomment-3252638"}}}
Discussion options

You must be logged in to vote

For example, if I clone some project which rely on dependencies hosted on GitHub Packages maven repo I’ll fail to compile it. Will have to investigate what the heck is going on. Figure out that I need to register on GitHub. Then generate token. Store in in ~/.m2/settings.xml . And only then the project might compile.

There are a few thing you can do to make this a little less painful.

  1. Create a settings.xml file at the root of your repository
  2. Create a .mvn/maven.config file that contains -s settings.xml
  3. Generate a PAT with just the read:packages scope

If your repository is private, you can place the PAT directly in your settings.xml file. If your repository is public, you can’t push t…

Replies: 47 comments 45 replies

Comment options

You must be logged in to vote
1 reply
@aSemy
Comment options

Comment options

You must be logged in to vote
5 replies
@nbrugger-tgm
Comment options

@Siedlerchr
Comment options

@glelouet
Comment options

@pmeister
Comment options

@sixcorners
Comment options

Comment options

You must be logged in to vote
2 replies
@pmdevita
Comment options

@vikulin
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@pmeister
Comment options

Comment options

You must be logged in to vote
5 replies
@Siedlerchr
Comment options

@jo-elimu
Comment options

@tr7zw
Comment options

@jo-elimu
Comment options

@lagergren
Comment options

Comment options

You must be logged in to vote
1 reply
@vikulin
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
14 replies
@glelouet
Comment options

@vikulin
Comment options

@vikulin
Comment options

@Andre601
Comment options

@vikulin
Comment options

Comment options

You must be logged in to vote
1 reply
@danielgerlag
Comment options

Comment options

You must be logged in to vote
3 replies
@nbrugger-tgm
Comment options

@vikulin
Comment options

@vikulin
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@vikulin
Comment options

@nort3x
Comment options

@kasperk81
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@vikulin
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions Build, test, and automate your deployment pipeline with world-class CI/CD Packages Host your dependencies, libraries, and production-ready code, right from your repository Product Feedback Share your thoughts and suggestions on GitHub features and improvements