2

I am working on a Liferay workspace project. How can I setup the credentials for a maven repository in some external file like gradle.properties in home folder and use it in settings.gradle. I know the above setting will work for build.gradle, but i needed the same for settings.gradle currently my settings.gradle is like below,

buildscript {
    dependencies {
        classpath group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "latest.release"
        classpath group: "net.saliman", name: "gradle-properties-plugin", version: "1.4.6"
    }

    repositories {
        maven {
            credentials {
                username 'user'
                password 'pw'
            }
            url "https://<host>/<url>"
        }
    }
}
Livin
  • 41
  • 1
  • 8
  • 1
    Did you try? What did not work? You should be able to reference `~/.gradle/gradle.properties` properties from `settings.gradle` – Louis Jacomet Jun 29 '18 at 08:35
  • Thanks for the response, The below snippet is working fine when the dependencies are avialable in ".gradle/caches/modules-2/files-2.1/com.liferay/com.liferay.gradle.plugins.workspace/" , If i delete the dependency , the downloading is not happening with the credentials from gradle.properties. If i hard-code the username and password , it starts working again. – Livin Jul 02 '18 at 07:17

1 Answers1

0

There is no much difference, here is an example from a settings.gradle In this example, the username and the password come from personal properties.

buildscript {

    dependencies { classpath "com.liferay:com.liferay.gradle.plugins.workspace:1.9.2" }

    repositories {
        maven {
            credentials {
                username = artifactory_username
                password = artifactory_password
            }
            url "https://example/artifactory/libs-release"
        }
    }
}
Victor
  • 3,520
  • 3
  • 38
  • 58
  • 1
    Thanks for the response, The above snippet is working fine when the dependencies are avialable in ".gradle/caches/modules-2/files-2.1/com.liferay/com.liferay.gradle.plugins.workspace/" , If i delete the dependency , the downloading is not happening with the credentials from gradle.properties. If i hard-code the username and password , it starts working again. – Livin Jul 02 '18 at 05:51
  • Huum, you might be using the wrong file for your properties. Are you using a wrapper? Did you configure you gradle home? Linux or windows? I asked because on Linux the apt will handle this for you. – Victor Jul 02 '18 at 12:19
  • yes I am using wrapper. GRADLE_HOME is not configured and it is an Ubuntu machine. Also I am using the same credentials which i have set in the gradle.properties in my build.gradle and it is working fine. The gradle.properties file is in my $HOME/.gradle folder – Livin Jul 04 '18 at 09:44
  • So, that is an issue, you will need to get your gradle home configured. As you are on ubuntu, you can also install from apt (don't worry it will not mess up your wrapper). Having the one from apt installed helps a lot, especially when you have several projects and they use different wrappers. For instance you can use the native one to create a wrapper in any project, and projects may need different wrapper versions. You do not need to stay with the terrible defaults Liferay uses. The common cache for your wrappers and everything will be on your home as well. – Victor Jul 04 '18 at 11:04