1+ /* Maven publish - start */
2+
3+ tasks. register(" sourcesJar" , Jar ) {
4+ archiveClassifier. set(" sources" )
5+ from sourceSets. main. allJava
6+ }
7+
8+ tasks. register(" javadocJar" , Jar ) {
9+ dependsOn tasks. named(" javadoc" , Javadoc )
10+ archiveClassifier. set(" javadoc" )
11+ from { tasks. named(" javadoc" , Javadoc ). get(). destinationDir }
12+ }
13+
14+ if (project. hasProperty(' mavenCentralUser' ) && project. hasProperty(' mavenCentralPassword' ) && project. hasProperty(' deployVersion' )) {
15+
16+ // snapshot version differs from normal version
17+ String versionString = project. getProperty(' deployVersion' )
18+
19+ publishing {
20+ publications {
21+ create(" mavenJava" , MavenPublication ) {
22+
23+ versionMapping {
24+ // resolves dynamic versioning to current version number
25+ usage(' java-api' ) {
26+ fromResolutionOf(' runtimeClasspath' )
27+ }
28+ usage(' java-runtime' ) {
29+ fromResolutionResult()
30+ }
31+ }
32+ pom {
33+ description = ' API to create modules and add-ons for simona'
34+ name = ' simonaAPI'
35+ url = ' https:github.com/ie3-institute/simonaAPI'
36+ organization {
37+ name = ' Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University'
38+ url = ' https:www.ie3.tu-dortmund.de/'
39+ }
40+ issueManagement {
41+ system = ' GitHub'
42+ url = ' https:github.com/ie3-institute/simonaAPI/issues'
43+ }
44+ licenses {
45+ license {
46+ name = ' BSD 3-Clause License'
47+ url = ' https:github.com/ie3-institute/simonaAPI/blob/master/LICENSE'
48+ }
49+ }
50+ developers {
51+ developer {
52+ organization = " Institute of Energy Systems, Energy Efficiency and Energy Economics (ie3)/TU Dortmund University"
53+ organizationUrl = " https:ie3.etit.tu-dortmund.de"
54+ }
55+ }
56+ scm {
57+ connection = ' scm:git:git:github.com/ie3-institute/simonaAPI.git'
58+ developerConnection = ' scm:git:ssh:github.com:ie3-institute/simonaAPI.git'
59+ url = ' https:github.com/ie3-institute/simonaAPI'
60+ }
61+ }
62+
63+ removeTestDependenciesFromPom(pom)
64+ groupId = group
65+ artifactId = ' simonaAPI'
66+ version = versionString
67+
68+ from components. java
69+ artifact sourcesJar
70+ artifact javadocJar
71+ }
72+ }
73+ repositories {
74+ maven {
75+ name = " MavenCentral"
76+ url = " https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
77+ credentials {
78+ username = project. findProperty(' mavenCentralUser' )
79+ password = project. findProperty(' mavenCentralPassword' )
80+ }
81+ }
82+ }
83+ signing {
84+ useInMemoryPgpKeys(
85+ findProperty(' signingKey' ) as String ,
86+ findProperty(' signingPassword' ) as String
87+ )
88+ sign publications. mavenJava
89+ }
90+ }
91+
92+ tasks. named(" generatePomFileForMavenJavaPublication" ) {
93+ destination = layout. buildDirectory. file(" generated-pom.xml" ). get(). asFile
94+ }
95+ }
96+
97+ def removeTestDependenciesFromPom (pom ) {
98+ pom. withXml {
99+ def root = asNode()
100+ // eliminate test-scoped dependencies (no need in maven central POMs)
101+ root. dependencies. removeAll { dep ->
102+ dep. scope == " test"
103+ }
104+ }
105+ }
106+
107+ /* Maven publish - end */
0 commit comments