using a GitHub Packages hosted repo in a Java/maven action #25160
-
Hello there, I tried to look up the search function and the available sections, but couldn’t find a better spot. If there is one please feel free to point me to it. Topic: I want to develop a client in Java for the mixer.com API. mixer has their package hosted on a GitHub Packages repo instead of pushing it to maven central. After a bit of tinkering I got it to work in NetBeans 11.2 by using the settings.xml in the ~/.m2/ directory so I’m able to build it local on my machine. As I also want to use the simple maven flow I struggle to get it to work. My current setup looks like this (as found in some other topic here):
I also had already a few hours staring at the documentation, but I just can’t get it to work. The codeflow always ends up with this issue:
So, my simple question comes down to this: What information do I have to put where to make the simple maven codeflow work correctly to access a repo hosted on GitHub Packages using this special GITHUB-TOKEN thing? I already put several hours just into this to get it working - but still wasn’t able to get it one single time. Any help appreciated. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
So I have copied from this one: https://github.community/t5/GitHub-Actions/GitHub-Package-Registry-with-Maven-causes-deployment-issues/m-p/39879
But isn’t there any other way than using some actiong someone provides for free - wich may could change at any time? |
Beta Was this translation helpful? Give feedback.
-
@cryptearth You could add settings.xml in the root path of your repo, you could refer to this article: You could use ${env.PASSWORD} in the settings.xml.
And in your workflow, add environment variable PASSWORD with the value of your personal access token stored in secrets. And add --settings parameter for mvn command.
I noticed that you are using GITHUB_TOKEN for the password, in the official document, it is asked to use a PAT. |
Beta Was this translation helpful? Give feedback.
-
@yanjingzhu thank you for your reply.
Do you have any sources from where you got that? As the doc you linked only links to another page only explaining GITHUB_TOKEN. I didn’t read anything about
Also: Although adding a settings.xml to the repo and specify it in the mvn command in the workflow may is a solution it would also mean that in each clone and fork of the repo it get copied around as well wich may could end up my username spreading around with me losing controll over it. I’d rather not want this to happen. Is there a way to mark a file to not get cloned/forked? In addition to this it will only work in the workflow. So if someone clones it and uses the --settings switch local for what ever reason it would break. I’d prefer to not break other peoples stuff. |
Beta Was this translation helpful? Give feedback.
-
@cryptearth Sorry for the mistake I’ve been made. Yes , you could use GITHUB_TOKEN in GitHub Actions workflow. For the username issue, it doesn’t matter what’s the value it is. You could use github.actor context .
Then change the settings.xml <servers> section to :
There is not a way to restrict a file to be cloned/forked. And, you are right, this could only works in workflow. If someone clones the repo to their local side and try to build the maven package in local, they need to follow the doc I linked before to change their local settings.xml with their personal access token. |
Beta Was this translation helpful? Give feedback.
-
@yanjingzhu Thank you very much. I just implemented what you recommended and it works fine. NetBeans seem to have some shadowing issues as it blends in the ~/.m2/settings.xml instead of the project local settings.xml - but that doesn’t cause any issues with the git commit and push. The workflow goes green. This should be somewhere noted in the official doc. |
Beta Was this translation helpful? Give feedback.
@cryptearth Sorry for the mistake I’ve been made. Yes , you could use GITHUB_TOKEN in GitHub Actions workflow.
For the username issue, it doesn’t matter what’s the value it is. You could use github.actor context .
Then change the settings.xml <servers> section to :
There is not a way to restrict a file to be cloned/forked. And, you are right, this could only w…