0

I am trying to publish my gradle project to nexus but I need credentials for this. It only works if I specify them hardcoded in my subproject build.gradle. I do not want to have my username & password hardcoded in any file. I have found a way to provide them on the command line, but this only works for the root project and not for the subprojects.

Any tips?

Jali Tha
  • 1
  • 1

1 Answers1

0

You can use the Gradle credentials plugin, a plugin that allows to store and access encrypted credentials using password-based encryption.

Benjamin Muschko
  • 32,442
  • 9
  • 61
  • 82
  • Thanks, I will look into it! However, so far nothing has worked in the subprojects except directly placing the credentials there. Prompting for credentials failed, adding credentials in a user gradle.properties failed, etc. All these things **do** work in the root project. – Jali Tha Jul 25 '16 at 08:27
  • Please provide an example project that demonstrates the issue - preferably on GitHub. – Benjamin Muschko Jul 25 '16 at 13:59
  • I have now found a way to ask for the credentials on the command line and have this forwarded to all the subprojects. This works okay, but it is happening for each task, which is not very nice. I will work on a minimal reproduction project later on when we will try to improve our script. For now this is sufficient as the deadline is nearing. Thanks for your time! – Jali Tha Jul 25 '16 at 15:44
  • Look into `gradle.taskGraph.whenReady` to be more selective about which task should ask for the credentials. – Benjamin Muschko Jul 25 '16 at 16:05
  • We changed from the maven-publish plugin to use the uploadArchives from the maven-plugin. We still had the authentication problems, but finally we managed to find the problem. We really had to get the authentication object and set the username there. If we did this then it also worked properly for the subprojects. Code snippit: `def auth = subproject.uploadArchives.repositories.mavenDeployer.getRepository().getAuthentication() auth.setUserName(project.nexusUser)` – Jali Tha Aug 15 '16 at 09:23