Last active
November 25, 2018 07:23
-
-
Save vinaysshenoy/b92cc84c98858b9d4416eb09bf25f40b to your computer and use it in GitHub Desktop.
Publish To Maven (S3 Backed) using new plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply from: 'secrets.gradle' | |
group 'com.vinaysshenoy' | |
version '1.0-SNAPSHOT' | |
buildscript { | |
ext { | |
common = [ | |
kotlin: '1.3.10' | |
] | |
} | |
repositories { | |
mavenCentral() | |
jcenter() | |
} | |
dependencies { | |
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$common.kotlin" | |
} | |
} | |
apply plugin: 'kotlin' | |
apply plugin: 'java-library' | |
apply from: 'publish.gradle' | |
allprojects { | |
buildscript { | |
repositories { | |
mavenCentral() | |
jcenter() | |
} | |
} | |
repositories { | |
mavenCentral() | |
jcenter() | |
} | |
} | |
dependencies { | |
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7" | |
} | |
compileKotlin { | |
kotlinOptions.jvmTarget = "1.7" | |
} | |
compileTestKotlin { | |
kotlinOptions.jvmTarget = "1.7" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
signing.keyId= | |
signing.password= | |
signing.secretKeyRingFile= | |
myRepo.url= | |
myRepo.accessKey= | |
myRepo.secretKey= | |
artifact.groupId=com.vinaysshenoy | |
artifact.name=library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This configures all the publishing logic in a single file. | |
import java.time.LocalDateTime | |
import java.time.ZoneOffset | |
import java.time.format.DateTimeFormatter | |
apply plugin: 'maven-publish' | |
apply plugin: 'signing' | |
task sourcesJar(type: Jar) { | |
classifier = 'sources' | |
from sourceSets.main.allSource | |
} | |
task javadocJar(type: Jar) { | |
classifier = 'javadoc' | |
from javadoc.destinationDir | |
} | |
publishing { | |
publications { | |
library(MavenPublication) { | |
groupId project['artifact.groupId'] | |
artifactId project['artifact.name'] | |
version generateArtifactVersion() | |
from components.java | |
artifact sourcesJar | |
artifact javadocJar | |
} | |
} | |
repositories { | |
maven { | |
name = 'myRepo' | |
url = project['myRepo.url'] | |
credentials(AwsCredentials) { | |
accessKey project['myRepo.accessKey'] | |
secretKey project['myRepo.secretKey'] | |
} | |
} | |
} | |
} | |
// This generates a version based on timestamp. Can easily be changed for a static version. | |
static String generateArtifactVersion() { | |
def format = DateTimeFormatter.ofPattern("yyyy.LL.dd.HHmmss", Locale.ENGLISH) | |
def now = LocalDateTime.now(ZoneOffset.UTC) | |
return format.format(now) | |
} | |
signing { | |
sign publishing.publications.library | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This task loads the secrets (if they exist) from the secrets file and overrides the project properties. | |
// This gets executed during build configuration (all the time, should see if incremental support can be added). | |
task('loadSecrets') { | |
def secretsFile = file('secrets.properties') | |
if (secretsFile.exists()) { | |
def properties = new Properties() | |
properties.load(secretsFile.newReader()) | |
properties.propertyNames().each { String key -> | |
project[key] = properties.get(key) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signatory_credentials | |
# to generate the siging credentials | |
# This file should be excluded from version control | |
signing.keyId=keyId | |
signing.password=password | |
signing.secretKeyRingFile=filePath | |
myRepo.url=s3://<bucket> | |
myRepo.accessKey=IAM access key | |
myRepo.secretKey=IAM secret key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment