gradle 是否存储在 nexus 存储库中?

Is gradle stored in a nexus repo?

这是为了下载 gradle 本身。我试图尽可能轻松地将它缓存在公司网络中。如果gradle在上游的nexus repo中可用,那么我可以将包装器的distributionUrl指向内部nexus。

Maven 在 maven central 中可用,这很方便,我正试图找到类似的解决方案。 https://search.maven.org/search?q=g:org.apache.maven%20a:apache-maven

我确实找到了,但我想知道是否有更官方的东西。 https://github.com/hazendaz/gradle https://search.maven.org/search?q=g:com.github.hazendaz.gradle%20a:gradle

感谢您的宝贵时间

很遗憾没有。 Gradle 包装器 JAR 未发布到 Maven 存储库,例如 Nexus。

您可以在 this line where the actual download occurs. Digging further in you can see here 上看到 Gradle 使用较低级别的 Java 机制来下载包装器。

所有 Gradle 发行版都可以在这里找到:https://services.gradle.org/distributions/. If you look at the version information,有一个 JSON 文件包含最新的发行版本。我对管理 Nexus 并不完全熟悉,但是如果你能以某种方式创建某种插件来轮询该版本信息,那么你可以下载它,如果它还没有 available/cached 在 Nexus 中。

使用 Nexus 时,您可以为 https://services.gradle.org/distributions 创建一个 raw (proxy) 存储库。这将代理所有请求。

在此实例中,存储库被命名为 gradle-distributions。这允许您使用:

curl https://nexus.example-organisation.com/repository/gradle-distributions/gradle-6.9.1-wrapper.jar.sha256
e996d452d2645e70c01c11143ca2d3742734a28da2bf61f25c82bdc288c9e637

而不是:

curl https://services.gradle.org/distributions/gradle-6.9.1-wrapper.jar.sha256
e996d452d2645e70c01c11143ca2d3742734a28da2bf61f25c82bdc288c9e637

那么在gradle-wrapper.properties中你可以使用:

distributionUrl=https://nexus.example-organisation.com/repository/gradle-distributions/gradle-6.9.1-bin.zip

M.P提供的解决方案。 Korstanje 没有直接为我工作,b/c 我的 Nexus 版本不允许我代理原始网站。但是,我能够通过创建托管“站点”存储库实现类似的功能,然后使用此脚本将 Gradle bin 压缩包上传到我的存储库:

#/bin/bash

#
# This helper script will upload any file to 'Gradle Distributions' Nexus repo
#

NEXUS_ADMIN_USER=
GRADLE_BIN_ZIP_FILE=

if    [ -z "$NEXUS_ADMIN_USER" ] \
   || [ -z "$GRADLE_BIN_ZIP_FILE" ]
then
  echo "[=10=] <NEXUS_ADMIN_USER> <GRADLE_BIN_ZIP_FILE>"
  exit 1
fi

curl -v \
    --user $NEXUS_ADMIN_USER \
    --upload-file $GRADLE_BIN_ZIP_FILE \
    http://nexus-host:8081/nexus/content/sites/gradle-distributions/$GRADLE_BIN_ZIP_FILE

所以现在所有批准的 Gradle 发行版都可以在 Nexus-managed URL:

http://nexus-host:8081/nexus/content/sites/gradle-distributions/
  ├── gradle-3.5.1-bin.zip
  ├── gradle-7.4.1-bin.zip
  ├── gradle-7.4.2-bin.zip
  └── upload_gradle_distro.sh

最后一步修改gradle/wrapper/gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=http\://nexus-host\:8081/nexus/content/sites/gradle-distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists