Giriş
Herhangi bir Maven repository sunucusuna jar ve pom dosyalarını yüklemek içindir.
Tasks
Gradle menüsü altında şu menüleri
görürüzpublishing
publish : Artifactory veya Nexus'a Yükler
publishToMavenLocal : Yerel Maven'a yükler
Örnek
plugins {
id 'java-library'
id 'maven-publish'
}
publications alanına
- earLibrary(MavenPublication)
- warLibrary(MavenPublication)
- mavenJava(MavenPublication)
gibi şeyler yazılır. Böylece neyi publish edeceğini anlar
repositories alanına
url ve authentication yazılır
Ear Dosyası
Örnek
Şöyle yaparız
plugins {
id 'java-library'
id 'maven-publish'
id 'ear'
}
//Configure maven-publish plugin to publish ear file
publishing {
publications {
earLibrary(MavenPublication) {
artifact ear
}
}
}
jar.enabled = false
War Dosyası
Örnek
Şöyle yaparız
plugins {
id 'java-library'
id 'maven-publish'
id 'war'
}
//Configure maven-publish plugin to publish war file
publishing {
publications {
warLibrary(MavenPublication) {
from components.web
}
}
}
jar.enabled = false
Jar Dosyası
Örnek
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = 'ms-commons'
from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
pom {
name = 'MS Commons'
description = 'A concise description of my library'
url = 'http://www.example.com/library'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'johnd'
name = 'John Doe'
email = 'john.doe@example.com'
}
}
}
}
} //publications
repositories {
maven {
name = "MyJfrog" // optional target repository name
url = "https://foo.jfrog.io/artifactory/my-repo"
credentials {
username = System.getenv('ARTIFACTORY_USERNAME')
password = System.getenv('ARTIFACTORY_USER_PASSWORD')
}
}
}
}
1. Seçenekler
publish
Jenkins ile şöyle yaparız
def shouldDeployToArtifactory() {
return "${params.ARTIFACTORY_PUBLISH}" == "true"
}
if (shouldDeployToArtifactory()) {
stage("Push to Artifactory") {
echo "Publishing to Artifactory..."
withCredentials([usernamePassword(
credentialsId: 'ARTIFACTORY_PUBLISH',
passwordVariable: 'ARTIFACTORY_PASSWORD',
usernameVariable: 'ARTIFACTORY_USER')
]) {
runGradleSteps("publish")
}
}
}
2. Alanlar
repositories Alanı
Örnek
publishing {
publications {
}
repositories {
maven {
name = "MyRepo" // optional target repository name
url = "http://my.org.server/repo/url"
credentials {
username = 'alice'
password = 'my-password'
}
}
}
}
Örnek
allprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
publishing {
publications {
(MavenPublication) {
from components.java
}
} //publications
repositories {
maven {
url "s3://my.private.maven"
authentication {
awsIm(AwsImAuthentication)
} //authentication
} //maven"
} /repositories
} //publishing
} //allprojects
cp init-client.gradle build/client/init-client.gradle cd build/client &&
./gradlew --init-script init.gradle publish &&
cd -