Skip to content

Commit bf20126

Browse files
authored
Merge pull request #3 from joutvhu/development
Setup publication
2 parents e43aafb + f2fbb77 commit bf20126

File tree

3 files changed

+205
-10
lines changed

3 files changed

+205
-10
lines changed

.github/workflows/gradle-publish.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
2+
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle
3+
4+
name: Gradle Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: Set up JDK 8
22+
uses: actions/setup-java@v2
23+
with:
24+
java-version: '8'
25+
distribution: 'adopt'
26+
27+
- name: Write Secret Key Ring File
28+
uses: joutvhu/write-file@v1
29+
with:
30+
path: secrets/secret-key.gpg
31+
contents: ${{ secrets.GPG_SECRET_KEY_BASE64 }}
32+
write_mode: overwrite
33+
encoding: base64
34+
35+
- name: Write Gradle Properties File
36+
uses: joutvhu/write-file@v1
37+
with:
38+
path: gradle.properties
39+
contents: ${{ secrets.GRADLE_SECRET_PROPERTIES }}
40+
write_mode: overwrite
41+
42+
- name: Build with Gradle
43+
run: gradle clean build
44+
45+
- name: Get Current Release
46+
id: get_current_release
47+
uses: joutvhu/get-release@v1
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
51+
- name: Publish to Sonatype Packages
52+
run: gradle publishMavenPublicationToSonatypeRepository
53+
54+
- name: Publish to GitHub Packages
55+
if: ${{ steps.get_current_release.outputs.prerelease == false && steps.get_current_release.outputs.draft == false }}
56+
run: gradle publishMavenPublicationToGithubRepository

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ nb-configuration.xml
8989
## Visual Studio Code ##
9090
.vscode/
9191
.code-workspace
92+
93+
# Secrets
94+
gradle.properties
95+
secrets
96+

build.gradle

+144-10
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,163 @@
11
plugins {
22
id 'java'
3+
id 'idea'
4+
id 'groovy'
5+
id 'signing'
6+
id 'maven-publish'
37
}
48

59
group 'com.github.joutvhu'
6-
version '1.0.0-SNAPSHOT'
10+
version '0.1.0-SNAPSHOT'
711
sourceCompatibility = 1.8
812
targetCompatibility = 1.8
913

14+
def snapshotVersion = version.endsWith('-SNAPSHOT') || version.endsWith('.SNAPSHOT')
15+
16+
configurations {
17+
compileOnly {
18+
extendsFrom annotationProcessor
19+
}
20+
}
21+
1022
repositories {
23+
mavenLocal()
1124
mavenCentral()
1225
}
1326

1427
dependencies {
15-
annotationProcessor 'org.projectlombok:lombok:1.18.12'
16-
compileOnly 'org.projectlombok:lombok:1.18.12'
28+
annotationProcessor 'org.projectlombok:lombok:1.18.20'
29+
compileOnly 'org.projectlombok:lombok:1.18.20'
1730

1831
implementation 'org.apache.commons:commons-lang3:3.12.0'
1932

20-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
21-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
33+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
34+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
35+
36+
testCompileOnly 'org.projectlombok:lombok:1.18.20'
37+
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
38+
}
39+
40+
jar {
41+
manifest {
42+
attributes 'Built-By': 'joutvhu (Giao Ho)'
43+
}
44+
into("META-INF/maven/${project.group}/${project.name}") {
45+
from {
46+
generatePomFileForMavenPublication
47+
}
48+
rename {
49+
it.replace('pom-default.xml', 'pom.xml')
50+
}
51+
}
52+
}
53+
54+
task fatJar(type: Jar) {
55+
manifest.from jar.manifest
56+
with jar
57+
}
58+
59+
task sourcesJar(type: Jar, dependsOn: classes) {
60+
classifier = 'sources'
61+
from sourceSets.main.allSource
62+
}
63+
64+
task javadocJar(type: Jar, dependsOn: javadoc) {
65+
classifier = 'javadoc'
66+
from javadoc.destinationDir
67+
}
68+
69+
artifacts {
70+
archives fatJar, sourcesJar, javadocJar
71+
}
2272

23-
testCompileOnly 'org.projectlombok:lombok:1.18.12'
24-
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
73+
tasks.withType(Test) {
74+
useJUnitPlatform {
75+
includeEngines 'junit-jupiter'
76+
}
77+
filter {
78+
includeTestsMatching 'com.joutvhu.date.parser.*'
79+
}
2580
}
2681

27-
test {
28-
useJUnitPlatform()
29-
}
82+
publishing {
83+
publications {
84+
maven(MavenPublication) {
85+
groupId = group
86+
artifactId = project.name
87+
artifacts = [fatJar, sourcesJar, javadocJar]
88+
version = version
89+
90+
pom {
91+
name = project.name
92+
description = 'Utility to parse String to Date by target type and string format'
93+
url = 'https://github.com/joutvhu/date-parser'
94+
licenses {
95+
license {
96+
name = 'MIT License'
97+
url = 'https://github.com/joutvhu/date-parser/blob/master/LICENSE'
98+
}
99+
}
100+
developers {
101+
developer {
102+
id = 'joutvhu'
103+
name = 'Giao Ho'
104+
105+
}
106+
}
107+
scm {
108+
connection = 'scm:git:[email protected]:joutvhu/date-parser.git'
109+
developerConnection = 'scm:git:[email protected]:joutvhu/date-parser.git'
110+
url = 'https://github.com/joutvhu/date-parser'
111+
}
112+
issueManagement {
113+
system = 'Github Issue'
114+
url = 'https://github.com/joutvhu/date-parser/issues'
115+
}
116+
organization {
117+
name = 'Giao Ho'
118+
url = 'https://github.com/joutvhu'
119+
}
120+
withXml {
121+
def dependenciesNode = asNode().appendNode('dependencies')
122+
123+
configurations.implementation.allDependencies.each {
124+
def dependencyNode = dependenciesNode.appendNode('dependency')
125+
dependencyNode.appendNode('groupId', it.group)
126+
dependencyNode.appendNode('artifactId', it.name)
127+
dependencyNode.appendNode('version', it.version)
128+
}
129+
}
130+
}
131+
}
132+
}
133+
repositories {
134+
maven {
135+
name = 'sonatype'
136+
if (snapshotVersion) {
137+
url = 'https://oss.sonatype.org/content/repositories/snapshots'
138+
} else {
139+
url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
140+
}
141+
credentials {
142+
username = project.ossrhUsername
143+
password = project.ossrhPassword
144+
}
145+
}
146+
maven {
147+
name = 'github'
148+
url = 'https://maven.pkg.github.com/joutvhu/date-parser'
149+
credentials {
150+
username = project.githubUsername
151+
password = project.githubPassword
152+
}
153+
}
154+
}
155+
}
156+
157+
signing {
158+
sign publishing.publications.maven
159+
}
160+
161+
tasks.publishMavenPublicationToGithubRepository.configure {
162+
onlyIf { !snapshotVersion }
163+
}

0 commit comments

Comments
 (0)