Gradle 依赖解决配置文件问题

Gradle dependency resolve Issue with profile

我已经在其中构建了一个 Maven 项目 A,其中 build.xml 包括使用另一个 pom 导入的所有测试依赖项。 当我试图将该 Maven 项目 A 包含到 gradle 项目 B 时 它给出了错误。

我先尝试使用 [--info] 它会尝试正确的存储库 url 并更新 jar [缓存的资源是最新的]。但最后它会尝试其他人并抛出错误。

如何从 gradle 构建文件传递配置文件名称?

感谢帮助。

项目 A -> Maven 构建 - pom.xml

<groupId>com.spring.test</groupId>
<artifactId>Rest</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Project</name>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <JUnitBOM.version.number>1.0.0</JUnitBOM.version.number>        
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
    <dependencies>
        <!-- Components -->
        <dependency>
            <groupId>com.test</groupId>
            <artifactId>JUnitBOM</artifactId>
            <version>${JUnitBOM.version.number}-${project.qualifier}
           </version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

    <profile>
        <id>AUAT</id>
        <properties>
            <env>uat</env>              
            <project.qualifier>SNAPSHOT</project.qualifier>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>

项目 B -> gradle 构建 - build.gradle

apply plugin: 'java'
apply plugin: 'maven'

group = "com.spring.integration" 
status = 'integration' 
version = '1.0.0' 
sourceCompatibility = 1.7

repositories {   
  maven { url "http://repo1" }  
  maven { url "http://maven.springframework.org/release" }   
  maven { url "http://maven.restlet.org" } }

dependencies {   
  compile group:'com.spring.test', name:'Rest', version:'1.0.0-SNAPSHOT', classifier: 'AUAT'    
  compile group:'org.restlet.jee', name:'org.restlet', version:'2.2'   
  compile group:'org.restlet.jee', name:'org.restlet.ext.servlet',version:'1.1'   
  compile group:'org.springframework', name:'spring-web',    version:'3.2.1.RELEASE'   
  compile group:'org.slf4j', name:'slf4j-api', version:'1.7.2'   
  compile group:'ch.qos.logback', name:'logback-core', version:'1.0.9'   
  testCompile group:'junit', name:'junit', version:'4.11' 

}

错误信息

Could not resolve all dependencies for configuration ':compile'.
> Could not resolve com.spring.test:Rest:1.0.0-SNAPSHOT.
  Required by:
  com.spring.test:0.1.0-SNAPSHOT
> Could not resolve com.test:JUnitBOM:1.0.0-${project.qualifier}.
  > java.lang.IllegalArgumentException (no error message)
  > java.lang.IllegalArgumentException (no error message)
  > java.lang.IllegalArgumentException (no error message)
> Could not HEAD 'http://maven.restlet.org/com/spring/test/Rest/1.0.0-SNAPSHOT/Rest-1.0.0-SNAPSHOT.pom'. Received status code 409 from server: Conflict

您可以使用 Gradle maven 设置插件 https://plugins.gradle.org/plugin/net.linguica.maven-settings。 配合maven设置插件,可以通过activeProfiles,自定义maven设置文件