Java 对渐变构建使用非标准Maven回购位置

Java 对渐变构建使用非标准Maven回购位置,java,maven,gradle,Java,Maven,Gradle,对于构建自动化,我们使用非标准的Maven存储库位置,该位置在如下设置文件中定义: <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

对于构建自动化,我们使用非标准的Maven存储库位置,该位置在如下设置文件中定义:

<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">

  <localRepository>/some/place/repository</localRepository>
     ... other stuff
</settings>
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'maven-publish'

group = 'com.example'
version = '1.3.4'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    ....
}

task uberJar(type: Jar) {
    description = 'Make JAR with all the dependencies included'
    classifier = 'uber'
    dependsOn configurations.runtime
    from sourceSets.main.output
    from { configurations.runtime.collect { it.directory ? it : zipTree(it) } }
}

task sourceJar(type: Jar) {
    description = 'Make JAR of all the source files'
    classifier = 'sources'
    from sourceSets.main.allSource
}

publishing {
    publications {
        maven(MavenPublication) {
            from components.java
            artifact sourceJar
            artifact jar
        }
    }
}
publishing {
  repositories {
    maven {
      url file('/some/place/repository')
    }
  }
  publications {
    maven(MavenPublication) {
      from components.java
      artifact sourceJar
      artifact jar
    }
  }
}
我试图在每个描述中添加此项


但是gradle仍然把东西放到
~/.m2/存储库中。我该如何做呢?

我认为您需要将
存储库
声明和
出版物
放在相同的
发布
块中,如下所示:

<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">

  <localRepository>/some/place/repository</localRepository>
     ... other stuff
</settings>
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'maven-publish'

group = 'com.example'
version = '1.3.4'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    ....
}

task uberJar(type: Jar) {
    description = 'Make JAR with all the dependencies included'
    classifier = 'uber'
    dependsOn configurations.runtime
    from sourceSets.main.output
    from { configurations.runtime.collect { it.directory ? it : zipTree(it) } }
}

task sourceJar(type: Jar) {
    description = 'Make JAR of all the source files'
    classifier = 'sources'
    from sourceSets.main.allSource
}

publishing {
    publications {
        maven(MavenPublication) {
            from components.java
            artifact sourceJar
            artifact jar
        }
    }
}
repositories {
    maven {
        url file('/some/place/repository')
    }
} 
publishing {
  repositories {
    maven {
      url file('/some/place/repository')
    }
  }
  publications {
    maven(MavenPublication) {
      from components.java
      artifact sourceJar
      artifact jar
    }
  }
}
另外,添加@lance java答案中的代码片段,以使自定义repo中的工件可用于其他项目:

repositories {
  mavenLocal()
  mavenCentral()
  maven {
    url file('/some/place/repository')
  }
}

下面两个答案都不适合我。行为没有改变。我决定创建一个maven pom要比弄明白如何让gradle做我想让它做的事情简单…你可能没有使用正确的gradle任务。我补充一个类似的问题。使用“PublishToAvenLocal”发布到.m2目录,而“PublishMavenJavaPublicationToAvenRepository”发布到我的非标准位置。