All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wttch.plugin.libs.publish.Repositories.kt Maven / Gradle / Ivy

The newest version!
package com.wttch.plugin.libs.publish

import com.wttch.plugin.libs.Constants
import com.wttch.plugin.libs.Constants.KEY_MAVEN_REPO_PASSWORD
import com.wttch.plugin.libs.Constants.KEY_MAVEN_REPO_USERNAME
import com.wttch.plugin.libs.exts.getProperty
import com.wttch.plugin.libs.exts.isReleaseVersion
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.api.publish.PublishingExtension

/**
 *
 * 根据版本自动区分仓库链接.
 *
 * 并自动从环境变量或者 local.properties 中加载账号密码
 *
 */
fun PublishingExtension.sonatypeAutoRepositories(project: Project) {
    repositories {
        it.sonatypeMaven(project)
    }
}

fun RepositoryHandler.sonatypeMaven(project: Project) {
    maven {
        val url =
            if (project.isReleaseVersion()) Constants.MAVEN_RELEASE_URL else Constants.MAVEN_SNAPSHOT_URL
        it.url = project.uri(url)
        it.loadCredentials(project)
    }
}

fun MavenArtifactRepository.loadCredentials(project: Project) {
    credentials {
        it.username = project.getProperty(KEY_MAVEN_REPO_USERNAME)
        it.password = project.getProperty(KEY_MAVEN_REPO_PASSWORD)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy