如何告诉gradle构建并上传依赖项目的归档到本地maven [英] how to tell gradle to build and upload archives of dependent projects to local maven
问题描述
我有一个多项目问题,Gradle的文档没有任何信息(并且在stackoverflow上也找不到)。任何帮助/指导将不胜感激。
以下是我的项目布局:
- project LeftArm :生成一个jar文件
- 项目 RightArm :生成一个jar文件
- project AllArms :取决于项目 LeftArm 和 RightArm ,并生成
war
文件
当我在 AllArms 项目中运行'gradle build uploadArchives'时,它会生成 LeftArm em>和 RightArm 项目,但不会上传 jar
文件(由 LeftArm 和 RightArm
以下是我的 build.gradle
文件:
project LeftArm:
apply plugin:'java'
apply plugin:'eclipse '
apply plugin:'idea'
apply plugin:'maven'
ext.artifactId ='LeftArm'
archivesBaseName = ext.artifactId //设置warfile / jarfile输出的文件名
group ='mygroup'
version ='1.0'
buildscript
{
版本库
{
mavenLocal()
}
}
jar
{
from(sourceSets ['main']。allJava )
}
依赖关系
{
编译组:'javax.validation',名称:'validation-api',版本:'1.0.0.GA'
编译组:'javax.validation',名称:'validation-api-sources',版本:'1.0.0.GA'
}
def localRepoURL ='文件://'+ new File(System.getProperty('user.home'),'.m2 / repository')。absolutePath
//注意:此项目将发布到本地Maven回购。
uploadArchives
{
repositories
{
mavenDeployer
{
repository(url:localRepoURL)
addFilter('jar')
{
artifact,file - > artifact.ext =='jar'
}
}
}
}
...
项目RightArm:
apply plugin :'java'
apply plugin:'eclipse'
apply plugin:'idea'
apply plugin:'maven'
ext.artifactId ='RightArm'
archivesBaseName = ext.artifactId //设置warfile / jarfile输出的文件名
group ='mygroup'
version ='1.0'
buildscript
{
存储库
{
mavenLocal()
}
}
jar
{
from(sourceSets ['main '] .allJava)
}
依赖关系
{
编译组:'javax.validation',名称:'validation-api',版本:'1.0。 0.GA'
编译组:'javax.validation',名称:'validation-api-sources',版本:'1.0.0.GA'
}
def localRepoURL ='file://'+ new File(System.getProperty('user。 home'),'.m2 / repository')。absolutePath
//注意:这个项目会发布到本地Maven仓库。
uploadArchives
{
repositories
{
mavenDeployer
{
repository(url:localRepoURL)
addFilter('jar')
{
artifact,file - > artifact.ext =='jar'
}
}
}
}
...
项目AllArms:
apply plugin :'java'
apply plugin:'war'
apply plugin:'maven'
apply plugin:'idea'
apply plugin:'eclipse'
ext.artifactId ='AllArms'
ext.sourceCompatibility = 1.6
archivesBaseName = artifactId //设置warfile / jarfile输出的文件名
group ='mygroup'
version =' 1.0'
def gwtVersion ='2.2.0'
储存库
{
mavenLocal()
mavenCentral()
}
依赖项
{
编译项目(':LeftArm')
编译项目(':RightArm')
// ###注意:这是构建中断b / c uploadArchives任务未执行的位置###
编译组:group,name:'LeftArm',版本:version
编译组:group,name: RightArm',版本:版本
providedCompile组:'javax.validation',名称:'validation-api',版本:'1.0.0.GA'
providedCompile组:'javax.validation',名称:'validation-api-sources',版本:'1.0.0.GA'
providesCompile组:'com.google.gwt',名称:'gwt-user',版本:gwtVersion
providedCompile组:'com.google.gwt',名称:'gwt-dev',版本:gwtVersion
providesCompile组:'org.gwtext',名称:'gwtext',版本:'2.0.4'
}
任务compileGwt(dependsOn:classes,类型:JavaExec){
project.ext
{
gwtDir =$ {project.buildDir} / gwt
extraDir =$ {project.buildDir} / extra
gwtModuleName ='MyModuleName'
}
inputs.source sourceSets.main.java.srcDirs
inputs.dir sourceSets.main.output.resourcesDir
outputs.dir project.gwtDir
//增量构建的解决方法(GRADLE-1483)
out puts.upToDateSpec = new org.gradle.api.specs.AndSpec()
doFirst
{
file(project.gwtDir).mkdirs()
}
main ='com.google.gwt.dev.Compiler'
classpath
{
[
sourceSets.main.java.srcDirs ,// Java源
sourceSets.main.output.resourcesDir,//生成资源
sourceSets.main.output.classesDir,//生成的类
sourceSets.main.compileClasspath,// Deps
]
}
args =
[
project.gwtModuleName,//您的GWT模块
'-war',project.gwtDir ,
'-logLevel','INFO',
'-localWorkers','2',
'-compileReport',
'-extra',project.extraDir,
]
maxHeapSize ='256M'
}
buildscript
{
存储库
{
mavenLocal()
}
}
sourceSets $ include('** / client / **')。include(()){
{srcDir('src / main / java')。include '** / public / **')。include('** / *。gwt.xml')
}
}
}
war.dependsOn (compileGwt)
war
{
def gwtOutputTree = project.fileTree(project.gwtDir)$ b $ from(gwtOutputTree)
baseName = artifactId
}
任务classesJar(type:Jar){
dependsOn(classes)
baseName = artifactId
}
artifacts
{
archives war,classesJar
}
def localRepoURL ='file://'+ new File(System.getProperty('user.home'),'.m2 / repository') .absolutePath
//注意:此项目将发布到本地Maven回购。
uploadArchives
{
repositories
{
mavenDeployer
{
repository(url:localRepoURL)
addFilter( '战争')
{
工件,文件 - > artifact.ext =='war'
}
}
}
}
uploadArchives
并不意味着用于安装到本地Maven存储库。相反,请使用安装
任务。
I have a multi-project problem that Gradle's documentation doesn't have any info on (and can't find on stackoverflow also). Any help/guidance will be greatly appreciated.
Here are my project layouts:
- project LeftArm: produces a jar file
- project RightArm: produces a jar file
- project AllArms: depends on projects LeftArm and RightArm and produces a
war
file
When I run 'gradle build uploadArchives' in AllArms project, it builds LeftArm and RightArm projects but it doesn't upload the jar
files (produced by LeftArm and RightArm projects) to local Maven repo.
Here are my build.gradle
files:
project LeftArm:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'
ext.artifactId = 'LeftArm'
archivesBaseName = ext.artifactId // sets filename of warfile/jarfile output
group = 'mygroup'
version = '1.0'
buildscript
{
repositories
{
mavenLocal()
}
}
jar
{
from(sourceSets['main'].allJava)
}
dependencies
{
compile group: 'javax.validation', name:'validation-api', version:'1.0.0.GA'
compile group: 'javax.validation', name:'validation-api-sources', version:'1.0.0.GA'
}
def localRepoURL = 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath
// NOTE: this project will publish to the local Maven repo.
uploadArchives
{
repositories
{
mavenDeployer
{
repository(url: localRepoURL)
addFilter('jar')
{
artifact, file -> artifact.ext == 'jar'
}
}
}
}
...
project RightArm:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'
ext.artifactId = 'RightArm'
archivesBaseName = ext.artifactId // sets filename of warfile/jarfile output
group = 'mygroup'
version = '1.0'
buildscript
{
repositories
{
mavenLocal()
}
}
jar
{
from(sourceSets['main'].allJava)
}
dependencies
{
compile group: 'javax.validation', name:'validation-api', version:'1.0.0.GA'
compile group: 'javax.validation', name:'validation-api-sources', version:'1.0.0.GA'
}
def localRepoURL = 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath
// NOTE: this project will publish to the local Maven repo.
uploadArchives
{
repositories
{
mavenDeployer
{
repository(url: localRepoURL)
addFilter('jar')
{
artifact, file -> artifact.ext == 'jar'
}
}
}
}
...
project AllArms:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: 'eclipse'
ext.artifactId = 'AllArms'
ext.sourceCompatibility = 1.6
archivesBaseName = artifactId // sets filename of warfile/jarfile output
group = 'mygroup'
version = '1.0'
def gwtVersion = '2.2.0'
repositories
{
mavenLocal()
mavenCentral()
}
dependencies
{
compile project(':LeftArm')
compile project(':RightArm')
// ### NOTE: this is where the build breaks b/c uploadArchives task is not executed ###
compile group: group, name: 'LeftArm', version:version
compile group: group, name: 'RightArm', version:version
providedCompile group: 'javax.validation', name:'validation-api', version:'1.0.0.GA'
providedCompile group: 'javax.validation', name:'validation-api-sources', version:'1.0.0.GA'
providedCompile group: 'com.google.gwt', name:'gwt-user', version:gwtVersion
providedCompile group: 'com.google.gwt', name:'gwt-dev', version:gwtVersion
providedCompile group: 'org.gwtext', name:'gwtext', version:'2.0.4'
}
task compileGwt (dependsOn: classes, type: JavaExec) {
project.ext
{
gwtDir = "${project.buildDir}/gwt"
extraDir = "${project.buildDir}/extra"
gwtModuleName = 'MyModuleName'
}
inputs.source sourceSets.main.java.srcDirs
inputs.dir sourceSets.main.output.resourcesDir
outputs.dir project.gwtDir
// Workaround for incremental build (GRADLE-1483)
outputs.upToDateSpec = new org.gradle.api.specs.AndSpec()
doFirst
{
file(project.gwtDir).mkdirs()
}
main = 'com.google.gwt.dev.Compiler'
classpath
{
[
sourceSets.main.java.srcDirs, // Java source
sourceSets.main.output.resourcesDir, // Generated resources
sourceSets.main.output.classesDir, // Generated classes
sourceSets.main.compileClasspath, // Deps
]
}
args =
[
project.gwtModuleName, // Your GWT module
'-war', project.gwtDir,
'-logLevel', 'INFO',
'-localWorkers', '2',
'-compileReport',
'-extra', project.extraDir,
]
maxHeapSize = '256M'
}
buildscript
{
repositories
{
mavenLocal()
}
}
sourceSets
{
main
{
resources
{ srcDir('src/main/java').include('**/client/**').include('**/public/**').include('**/*.gwt.xml')
}
}
}
war.dependsOn(compileGwt)
war
{
def gwtOutputTree = project.fileTree(project.gwtDir)
from(gwtOutputTree)
baseName = artifactId
}
task classesJar(type: Jar) {
dependsOn(classes)
baseName = artifactId
}
artifacts
{
archives war, classesJar
}
def localRepoURL = 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath
// NOTE: this project will publish to the local Maven repo.
uploadArchives
{
repositories
{
mavenDeployer
{
repository(url: localRepoURL)
addFilter('war')
{
artifact, file -> artifact.ext == 'war'
}
}
}
}
uploadArchives
isn't meant to be used to install to the local Maven repository. Instead, use the install
task.
这篇关于如何告诉gradle构建并上传依赖项目的归档到本地maven的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!