LoginSignup
3

More than 5 years have passed since last update.

gradleでテストコードもjarにして、Mavenリポジトリにuploadする

Posted at

やりたいこと

複数のコンポから参照されているutilプロジェクトがある。
util のテストを作成する際に、テストのためのヘルパーメソッドを作ったが、他のコンポでもそのヘルパーメソッドを利用したい。

確認環境

  • gradle 3.2
  • java 1.8.0_45

構成

  • util
  • compoA

uitl

  • testコードのためのJarタスク(testJar)を追加し、artifacts に設定
    (include, excludeをつかってヘルパーメソッドだけ固めるほうがいいとは思います)
build.gradle
apply plugin: 'java'
apply plugin: 'maven'

repositories {
    jcenter()
}

dependencies {
    testCompile 'junit:junit:4.12'
}

group='testutil'
version=1.0

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "http://192.168.99.100:8080/repository/internal/"){
                authentication(userName: 'admin', password: 'xxxx')
            }
        }
    }
}

task testJar(type: Jar){
    classifier = 'tests'
    from sourceSets.test.output+sourceSets.test.allSource
}

artifacts {
    archives testJar
}

compoA

  • dependencies のtestCompile でclassifier付きで指定
build.gradle
apply plugin: 'java'

group='testutil'
version=1.0

repositories {
    maven {
        url 'http://192.168.99.100:8080/repository/internal/'
    }
    jcenter()

}


dependencies {
    compile 'testutil:util:1.0'
    testCompile 'testutil:util:1.0:tests'
    testCompile 'junit:junit:4.12'
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3