LoginSignup
1
0

More than 1 year has passed since last update.

TOMLファイル形式のVersionCatalogをMavenLocalに公開する

Posted at

はじめに

やろうと思った時にやり方を忘れていたのでメモ。

公開する側

build.gradle(.kts)の設定

rootのbuild.gradle(.kts)に、

  • 公開するために必要なプラグイン
  • 公開したいTOMLのパスの設定
  • 公開に関する設定

を追加する。

build.gradle.kts
plugins {
    id("version-catalog")
    id("maven-publish")
}

catalog {
    versionCatalog {
        from(files("gradle/libs.versions.toml"))
    }
}

publishing{
    publications{
        create<MavenPublication>("catalog"){
            //このfromの設定により、versionCatalogとして公開できる
            from(components["versionCatalog"])
            groupId = "com.sample"
            artifactId = "catalog-publishing-sample"
            version = "1.0.0"

        }
    }
}

MavenLocalに公開する

./gradlew PublishToMavenLocal
を叩くと、metadata,pom,module,tomlなどが生成される 

読み込む側

settings.gradle(.kts)の設定

読み込みたいプロジェクトのsettings.gradle(.kts)に

  • MavenLocal()の追加(dependencyResolutionManagementの中だけで◎)
  • MavenLovalに公開されてるgroup,artifact,versionを指定してのVersionCatalogの追加

を行う

settings.gradle.kts
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        mavenLocal()  //追加
    }
    versionCatalogs {
        create("mavenLocalLibs") {
            from("com.sample:catalog-publishing-sample:1.0.0")
        }
    }
}

読み込んだcatalogを使う

読み込み時につけた名前で使える。

build.gradle(:app)
implementation mavenLocalLibs.activity.compose

おしまい

参考
https://docs.gradle.org/current/userguide/publishing_maven.html
https://docs.gradle.org/current/userguide/platforms.html#sec:version-catalog-plugin

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