1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Maven Publish PluginでKotlinのソースコードを公開する

Last updated at Posted at 2020-07-24

概要

Maven Publish Plugin で kotlin のソースコードを添付する方法です。

build.gradle.kts(差分のみ)

以下、既に Maven Publish Plugin を利用している場合向けの、差分のみを示したコードです。
※ 各値は自身の環境に合わせてください

build.gradle.kts
tasks {
    val sourcesJar by creating(Jar::class) {
        archiveClassifier.set("sources")
        from(sourceSets["main"].allSource)
    }
}

afterEvaluate {
    publishing {
        publications {
            create<MavenPublication>("maven") {
                artifact(tasks["sourcesJar"])
            }
        }
    }
}

build.gradle.kts

build.gradle.kts の全体像のサンプルです。

plugins {
    `java-library`
    kotlin("jvm")
    `maven-publish`
}

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72")
}

tasks {
    compileKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    compileTestKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    val sourcesJar by creating(Jar::class) {
        archiveClassifier.set("sources")
        from(sourceSets["main"].allSource)
    }
}

afterEvaluate {
    publishing {
        publications {
            create<MavenPublication>("maven") {
                from(components["kotlin"])
                artifact(tasks["sourcesJar"])
                groupId = "com.example"
                artifactId = "foo-bar"
                version = "1.0.0"
            }
        }
    }
}

実行

./gradlew publishMavenPublicationToMavenLocal
1
1
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?