How can I download gradle depedencies with proxy and without proxy - gradle

I have a build.gradle and I download some dependencies with proxy, but there are some dependencies which give 403 forbidden error and will work without proxy. How Can this be possible that gradle build knows when to use proxy and when not

I resolved this by adding nonProxyhosts in gradle.properties file. Along with other Proxyhosts
systemProp.http.proxyHost=<proxy host>
systemProp.http.proxyPort=<proxy port>
systemProp.http.nonProxyHosts=<url of the host>
systemProp.https.proxyHost=<proxy host>
systemProp.https.proxyPort=<proxy port>
systemProp.https.nonProxyHosts=<url of the host>

Related

Idea (via Gradle) "Could not resolve:" dependencies from Sonatype Nexus Proxy of mavenCentral()

I have a hosted Sonatype Nexus repository on a local network. It has a Maven group containing a proxy repository for the public Maven repository. In the past this configuration was superb and I encountered few issues.
I recently configured https and ssl on the Nexus repository as Docker would not easily log into insecure Nexus Docker registries during CI/CD processes. I did end up re-configuring the Maven repositories at this point.
Then I updated build.gradle:
repositories {
maven {
credentials {
username "${nexusUsername}"
password "${nexusPassword}"
}
name = 'RepositoryName'
url = "https://${nexusURL}:${nexusPort}/repository/maven-public"
}
}
with the nexus* variables defined in ~/.gradle/gradle.properties:
nexus<Variable>=<value>
I have also added the appropriate certificate to the java jre keystore with the keytool and added the certificate in Idea's settings (File > Settings... : Tools > Server Certificates).
When trying to download dependencies (through the Maven proxy) using Gradle (by clicking "import changes" on the pop-up notification in Intellij Idea) the Build output shows "Could not resolve: <dependency>" for each dependency. This behavior is consistent across all of my projects (even ones that previously were able to resolve dependencies).
I have, under most circumstances, been able to get the dependencies to resolve through Nexus when running a Gradle task (:dependencies, :idea, :build) from the project's build.gradle file from a command line. The resulting downloads are not available to the project in Idea. However, after the dependencies have been resolved once, the artifacts are cached in Nexus's Maven proxy repository allowing Gradle/Idea to correctly resolve all dependencies.
What could be causing Gradle/Idea's failure to resolve artifacts through Nexus's Maven proxy? Is there a way to get Gradle/Idea to correctly resolve dependencies through the Nexus Maven group/proxy?
For now I've just added mavenCentral() to the repository list in build.gradle but I would prefer to only include the Nexus Maven group in the future. Caching resources for 1GB/s download is really nice. I would also like to better understand Gradle/Idea and what is causing this issue.
More information:
Intellij Idea has been reinstalled to version 2018.2.6 Build #IC-182.5107.16 during the process of trying to fix this issue. The old version is lost to history.
Gradle has been updated to version 4.10.2. Previous version was 4.5.1.
I've printed each of the nexus* variables via println to ensure the values were correct.
No configuration of Idea's settings for Gradle (local Gradle distribution, default Gradle wrapper, Gradle 'wrapper' task configuration) managed to resolve dependencies.
Every configuration of deleting at least one of ./.idea, ./.gradle, and ~/.gradle/caches was tried.
Idea is not in offline-mode. Sequences of toggling offline-mode and "Refresh all Gradle projects" did not change the outcome.
I have run an Idea configuration of Gradle's dependencies task with --warning-mode all --debug and compared the log to the output of gradle dependencies --warning-mode all --debug on command line. The logs seem to be producing the same statements (in wildly different orders) until the "Could not resolve:" message appears in the Idea output. I did not find any nearby error messages that would explain the failure. If it would help diagnose the issue I can upload those files.
I have tried setting the repository to point directly at the Nexus Maven proxy instead of the Maven group. This did not allow Gradle/Idea to resolve dependencies.
Should I be using a http/https proxy for Gradle? I don't understand the goal of using a proxy in this context.
I have not done anything with Grail. I don't know what Grail is and suspect I do not currently need it.
OS is Windows 10.
Dependencies are not resolved when using compile or implementation in build.gradle.
Transitive dependencies don't seem to be relevant.
I must not have added the certificate to the correct jre installation. I added it more recently and the issue was resolved.
Also, superstitious notes for anyone else having a similar issue:
I added the certificate (a wildcard certificate) under the alias (using the -alias command line parameter for keytool): *.example.com
I also added it under an alias for the full address: nexus.example.com
I don't know whether either of those had any impact on Idea/Gradles' success in resolving artifacts. I believe it was working before I added the second alias.

Nexus repo not accessible through proxy in maven settings

I have a maven project.
when I build using cmd prompt- It downloads the maven repos, only when the proxy is configured in settings.xml file.
But this proxy is blocking the nexus repos. I do have two nexus repos required for this project. and I get build error -- return code:503 reason phrase: service unavailable for nexus repo contents
If I follow the stack overflow answer Nexus Repo gives 503 with Maven but not with browser
and added proxy to nexus instance and mirrored the nexus in my settings file. Still maven repo works and nexus repos or not accessible.
my settings.xml
Any help would be appreciated.
Thanks in advance

How to configure Maven to not use proxy server

I am trying to configure Maven to not use a proxy server. This turns out to be a lot of work. Somewhere Maven has read some proxy information which it keeps on using.
I tried the following already.
in the terminal unset http_proxy and https_proxy
I did not have a settings.xml. I added one and added a proxy config to it with active is false
In settings.xml active = true and nonProxyHosts = *
I remove proxy settings from /etc/environment
I don't want to install a local proxy server just to get this working, is there another way to tell Maven not to use a proxy server.
The first step is to ask Maven to show you what configuration it sees/uses. Use the Help plugin for this: mvn help:effective-pom shows you the complete POM that Maven will use and help:effective-settings will do the same for the settings.xml.
Now you can see whether there are any proxy settings in those outputs, just to make sure the Maven universe is clean. My guess is that someone changes the global/default settings.xml from the conf folder of your Maven installation.
Afterwards, you need to check the proxy options which Java uses. Check your environment and the file $HOME/.mavenrc

Change Maven settings at build time

I would like to deploy my Maven build to an Artifactory repo. This repo requires authentication, but I would prefer not modifying my settings.xml file. Is there a way to provide the credentials at build time? I know that you can set properties in the POM with the -D switch:
mvn clean package -Dmy.prop=blah
Is there a way to do something similar to provide the contents of a <server> block in the settings.xml file?
You can use the Maven Artifactory plugin, which accepts credentials in pom file and use the -D as intended.
And, of course, you'll get the full build-info support :)
You can prepare separate settings.xml file for build purpose and use this by -s options.
Eg.
mvn -s build_settings.xml clean deploy

Set a timeout to maven downloading resources?

I don't want maven to download from any repository...is there a way to set download time out from all the repository?
The offline tag set to "true" in settings.xml is helpless in this case.
Invoking mvn with the -o flag will stop Maven downloading dependencies from remote repositories.
e.g.:
mvn -o install

Resources