This message was deleted.
# community-support
s
This message was deleted.
v
Hard to say without a crystal ball. Look at the
--debug
log to see whether someone is going on or what happened last, and take a thread dump and analyze it to see where things are hanging if they really are.
h
Thanks. Found a network connection problem there, today I added a global repository in the
~/.gradel/init.gradle
.
Copy code
allprojects {
	buildscript {
		repositories {
			mavenLocal()
//			maven {
//				url "<https://myhost:5443/nexus/content/groups/public/>"
//				credentials {
//					username "hantsy"
//					password "XXX"
//				}
//			}
			mavenCentral()
			google()
		}
	}

    repositories {
		mavenLocal()
//		maven {
//			url "<https://myhost:5443/nexus/content/groups/public/>"
//			credentials {
//				username "hantsy"
//				password "XXX"
//			}
//	   }
		mavenCentral()
		google()
    }

}
The private maven repository(with credentials) is always connection time out, but the same credentials and url, it is working well in the m2/settings.xml.
v
Actually this snippet is a very bad idea. A build should configure the repositories it needs. Otherwise the builds only work, or work differently, on other machines than on your machine. Unless you always ever work with local projects that never see a different machine than yours. Then it would just be bad practice. Besides that
mavenLocal()
per-se, no matter where used, is a bad idea, especially as first repository and without content filter. It is broken by design (by Maven, not by Gradle), it will make your builds slow, unreliable, and flaky, and might miss Gradle Module Metadata for dependencies which could provide better dependency resolution as it is a richer model than POMs.
h
The private maven repository is just a mirror of the central maven repo and some open source repo, such as jboss, jakarta repos, only used to speed up download in a team and save time for work.
Always using Maven central is terrible, it could block my IP according to the maven principle. And in China, the download rate from maven central only 5k-10k, it is every slow.
Gradle design is good, like a piece of art, but its slow build and deps download is terrible for Chinese, so most of time I have to use Maven even it is design is not ideal.
v
The private maven repository is just a mirror of the central maven repo and some open source repo, such as jboss, jakarta repos, only used to speed up download in a team and save time for work.
Well, as I said, by that snippet you modify all builds to add those repositories first. So you change the behavior of the builds as you change the repositories that are available and the order too. So unless all builds you ever use have these repositories anyway, you might easily get into trouble. And with
mavenLocal()
anyway, especially if you also use Maven, because if you resolve a dependency with maven, it is stored to
mavenLocal()
, but only the files that were actually downloaded, so usually you now have incomplete and thus corrupt entries in that repository that is also misused as a cache directory by Maven. If you then try to use that dependency from Gradle, it sees the broken state but assumes it is good. This might go well if you are lucky, this might break in a loud and obvious way, or this might break in subtle ways you don't see right away and can spend a tremendous amount of time to find out why something is not working as expected. Besides that it makes your builds slow and not only unreliable and flaky. And to reuse the artifacts that are present in
mavenLocal()
to save the download time, you don't need that declaration, Gradle already automatically takes an artifact from there if it is present with the expected checksum as far as I remember.
Always using Maven central is terrible, it could block my IP according to the maven principle.
Why should it block your IP? According to what principle? Especially as Gradle does have a proper cache and does not re-download a dependency it already has in its cache.
And in China, the download rate from maven central only 5k-10k, it is every slow.
Yeah, it's fine to use a caching proxy that multiple people can use then. But you shouldn't just prefix each and every build with a list of repositories it maybe shouldn't have with an init script. You could for example add logic to your init script that checks whether Maven Central is present as repository and then replaces it by your proxy or something like that. I think something like this should work:
Copy code
def replaceMavenCentralWithProxy = { repository ->
    if (!(repository instanceof MavenArtifactRepository)) {
        return
    }
    if (repository.url.host == '<http://repo.maven.apache.org|repo.maven.apache.org>') {
        repository.tap {
            url = '<https://myhost:5443/nexus/content/groups/public/>'
            credentials {
                username "hantsy"
                password "XXX"
            }
        }
    }
}

def versionParts = gradle.gradleVersion.split('\\.')
def majorVersion = versionParts[0] as int
def minorVersion = versionParts[1].split('-')[0] as int

def handleSettings = { settings ->
    if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 5)) {
        settings.pluginManagement {
            if (majorVersion > 4 || (majorVersion == 4 && minorVersion >= 9)) {
                repositories.configureEach(replaceMavenCentralWithProxy)
            } else {
                repositories.all(replaceMavenCentralWithProxy)
            }
        }
    }
    if (majorVersion > 6 || (majorVersion == 6 && minorVersion >= 8)) {
        settings.dependencyResolutionManagement {
            repositories.configureEach(replaceMavenCentralWithProxy)
        }
    }
}

if (majorVersion >= 6) {
    beforeSettings(handleSettings)
} else {
    settingsEvaluated(handleSettings)
}

allprojects {
    buildscript {
        if (majorVersion > 4 || (majorVersion == 4 && minorVersion >= 9)) {
            repositories.configureEach(replaceMavenCentralWithProxy)
        } else {
            repositories.all(replaceMavenCentralWithProxy)
        }
    }
    if (majorVersion > 4 || (majorVersion == 4 && minorVersion >= 9)) {
        repositories.configureEach(replaceMavenCentralWithProxy)
    } else {
        repositories.all(replaceMavenCentralWithProxy)
    }
}
🎉 1