ext { artifactoryBaseUrl = 'http://maven.ubtob.net/artifactory' artifactorySnapshotRepoUrl = "$artifactoryBaseUrl/libs-snapshot-local" artifactoryReleaseRepoUrl = "$artifactoryBaseUrl/libs-release-local" } apply plugin: 'maven-publish' task sourcesJar(type: Jar) { baseName "${project.name}" classifier 'sources' from sourceSets.main.allSource } publishing { publications { plugin(MavenPublication) { groupId "${project.group}" artifactId "${project.name}" version "${project.version}" from components.java artifact sourcesJar } } repositories { maven { name 'myLocal' url "file://$projectDir/repo" } maven { name 'remoteArtifactory' url project.version.endsWith('-SNAPSHOT') ? artifactorySnapshotRepoUrl : artifactoryReleaseRepoUrl credentials { username = 'admin' password = 'Admin2020yourkj2021' } } } }