2017-01-06 75 views
0

我有一個gradle build,必須將預構建的jar文件作爲工件發佈。由於某種原因,它沒有被拾起。下面是一個簡化版本重現它:Gradle未發佈自定義jar神器

文件夾內容:

settings.gradle 
build.gradle 
some.jar 

settings.gradle:

rootProject.name = 'some' 

的build.gradle:

apply plugin: 'base' 
apply plugin: 'maven-publish' 

group = 'foo.bar' 
version = '1.0' 

task copyPrebuilt(type: Copy) { 
    from(projectDir) { 
    include 'some.jar' 
    rename 'some', "some-$version" 
    } 
    into distsDir 
} 

artifacts { 
    // should be 'archives'? 
    // http://stackoverflow.com/questions/39068090/gradle-archives-artifacts-not-populated-to-default-configuration 
    'default' (file("$distsDir/some-${version}.jar")) { 
    name 'some' 
    type 'jar' 
    builtBy copyPrebuilt 
    } 
} 

some-1.0.jar不會被複制到~/.m2/repository/foo/bar/some/1.0通過gradle publishToMavenLocal

任何線索?

回答

1

得到發表的東西,最簡單的方法是定義一個發佈對象:

apply plugin: 'base' 
apply plugin: 'maven-publish' 

group = 'foo.bar' 
version = '1.0' 

task copyPrebuilt(type: Copy) { 
    from(projectDir) { 
     include 'some.jar' 
     rename 'some', "some-$version" 
    } 
    into buildDir 
} 

publishToMavenLocal.dependsOn copyPrebuilt 

publishing { 
    publications { 
     prebuilt(MavenPublication) { 
      artifact file("$buildDir/some-${version}.jar") 
     } 
    } 
} 

此代碼publishToMavenLocal任務安裝一些-1.0.jar到本地Maven倉庫。