gradle不使用mavenLocal下载依赖项

时间:2019-07-28 23:19:37

标签: gradle build.gradle

我想将ci-nexus的依赖项下载到gradle Project中,作为我们的私有仓库之一。我正在使用.m2 / settings.xml中的url和凭据。在执行“ gradle clean build”时,它实际上使用来自settings.xml的凭据成功登录,但未在.gradle / cache中下载依赖项,而是继续在.m2 / repository文件夹中查找依赖项

我尝试使用自定义Maven Repo方法,并直接在build.gradle中提供URL和凭据,并且效果很好。但是绝对不希望将其硬编码到build.gradle中,因为我将通过Jenkins运行它,而我实际上是在运行jenkins build时动态地构建settings.xml。

allprojects {
    group = 'com.XYZ'
    version = '1.0.0-SNAPSHOT'
}

subprojects {
    apply plugin: 'java'
    apply plugin: 'groovy'
    apply plugin: 'idea'
    apply plugin: 'maven'
    apply plugin: 'maven-publish'
    apply plugin: 'pmd'
    apply plugin: 'findbugs'

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    repositories {
        mavenCentral()
        mavenLocal()
    }
}

从根目录运行时:gradle clean build -x test

* What went wrong:
Execution failed for task ':XYZ:compileJava'.
> Could not resolve all files for configuration ':XYZ:compileClasspath'.
   > Could not find com.XYZ:2017.36.1.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/com/../XYZ-2017.36.1.pom
       - https://repo.maven.apache.org/maven2/com/../XYZ-2017.36.1.jar
       - file:/Users/Thatsme/.m2/repository/com/../XYZ-2017.36.1.pom
       - file:/Users/Thatsme/.m2/repository/com/../XYZ-2017.36.1.jar
     Required by:
         project :XYZ

settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                           http://maven.apache.org/xsd/settings-1.0.0.xsd">                              
    <mirrors>
        <mirror>
            <id>nexus-ci</id>
            <mirrorOf>*,!company-local</mirrorOf>
            <url>https://ci-nexus.company.com/content/groups/public/</url>            
        </mirror>
    </mirrors>
    <servers>
        <server>
            <id>nexus-ci</id>
            <username>USERNAME</username>
            <password>PASSWORD</password>
        </server>
        <server>
            <id>company-local</id>
            <username>USERNAME</username>
            <password>PASSWORD</password>
        </server>
    </servers>

    <profiles>    
        <profile>
            <id>company-local</id>
            <activation>
              <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
               <nexus.company.repo>ci-nexus.company.com</nexus.company.repo>
            </properties>
            <repositories>
                <localRepository>
                    <id>company-local</id>
                    <url>https://ci-nexus.company.com/content/groups/local</url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </localRepository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>company-local</id>
                    <url>https://ci-nexus.company.com/content/groups/local</url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
</settings>

0 个答案:

没有答案