美文网首页
2024-01-27

2024-01-27

作者: Tony宇哲 | 来源:发表于2024-01-26 17:21 被阅读0次

    Library发布到私服Nexus仓库

    1. 配置Nexus仓库信息:在项目的根目录的build.gradle.kts文件中配置Nexus仓库的信息。

    2. 添加发布插件:在你的Library模块的build.gradle.kts文件中应用maven-publish插件。

    3. 配置发布任务:在同一个build.gradle.kts文件中,配置发布任务,包括groupId、artifactId、version等信息,以及仓库的url和凭证

    // 在项目根目录的 build.gradle.kts 中配置仓库信息

    allprojects {

        repositories {

            maven {

                url = uri("http://your-nexus-repository-url/repository/maven-releases/")

                credentials {

                    username = "your-nexus-username"

                    password = "your-nexus-password"

                }

            }

        }

    }

    // 在你的Library模块的 build.gradle.kts 中

    plugins {

        `maven-publish`

    }

    publishing {

        publications {

            create<MavenPublication>("release") {

                groupId = "com.example"

                artifactId = "your-library-name"

                version = "1.0.0"

                from(components["release"])

            }

        }

        repositories {

            maven {

                name = "Nexus"

                url = uri("http://your-nexus-repository-url/repository/maven-releases/")

                credentials {

                    username = "your-nexus-username"

                    password = "your-nexus-password"

                }

            }

        }

    }

    4. 发布Library:配置完成后,你可以通过执行发布任务将你的Library上传到Nexus仓库。在Android Studio的Terminal中运行以下命令:

    ./gradlew publish

    5. 在其他项目中使用该Library:在其他项目的build.gradle.kts文件中添加Nexus仓库的地址,并添加对你的Library的依赖。

    repositories {

        maven {

            url = uri("http://your-nexus-repository-url/repository/maven-releases/")

        }

    }

    dependencies {

        implementation("com.example:your-library-name:1.0.0")

    }

    repositories {

        maven {

            url = uri("http://your-nexus-repository-url/repository/maven-releases/")

        }

    }

    dependencies {

        implementation("com.example:your-library-name:1.0.0")

    }

    确保你的Nexus仓库地址、用户名、密码、groupId、artifactId和版本号等信息是正确的。这样,你就可以在Android Studio中使用Kotlin DSL将Library发布到私服Nexus仓库,并在其他项目中使用它了。

    相关文章

      网友评论

          本文标题:2024-01-27

          本文链接:https://www.haomeiwen.com/subject/knybodtx.html