@@ -39,6 +39,7 @@ plugins {
39
39
40
40
apply from : file( ' gradle/module.gradle' )
41
41
42
+
42
43
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43
44
// Release Task
44
45
@@ -61,19 +62,23 @@ task publish {
61
62
" themselves if they have any publish-related activities to perform"
62
63
}
63
64
64
- ext {
65
- if ( project. hasProperty( ' hibernatePublishUsername' ) ) {
66
- if ( ! project. hasProperty( ' hibernatePublishPassword' ) ) {
67
- throw new GradleException ( " Should specify both `hibernatePublishUsername` and `hibernatePublishPassword` as project properties" );
68
- }
65
+
66
+
67
+ def ossrhUsername = extractPropertyOrSetting( " OSSRH_USER" )
68
+ def ossrhPassword = extractPropertyOrSetting( " OSSRH_PASSWORD" )
69
+
70
+ String extractPropertyOrSetting (String name ) {
71
+ if ( project. hasProperty( name) ) {
72
+ return project. property( name )
69
73
}
74
+ return System . getProperty( name )
70
75
}
71
76
72
77
nexusPublishing {
73
78
repositories {
74
79
sonatype {
75
- username = project . hasProperty( ' hibernatePublishUsername ' ) ? project . property( ' hibernatePublishUsername ' ) : null
76
- password = project . hasProperty( ' hibernatePublishPassword ' ) ? project . property( ' hibernatePublishPassword ' ) : null
80
+ username = ossrhUsername
81
+ password = ossrhPassword
77
82
}
78
83
}
79
84
}
@@ -82,26 +87,15 @@ gradle.taskGraph.addTaskExecutionGraphListener(
82
87
new TaskExecutionGraphListener () {
83
88
@Override
84
89
void graphPopulated (TaskExecutionGraph graph ) {
85
- String [] tasksToLookFor = [
86
- ' publish' ,
87
- ' publishToSonatype' ,
88
- ' publishAllPublicationsToSonatype' ,
89
- ' publishPublishedArtifactsPublicationToSonatypeRepository' ,
90
- ' publishRelocationArtifactsPublicationToSonatypeRepository' ,
91
- ]
92
-
93
- for ( String taskToLookFor : tasksToLookFor ) {
94
- if ( graph. hasTask( taskToLookFor ) ) {
95
- // trying to publish - make sure the needed credentials are available
96
-
97
- if ( project. property( ' hibernatePublishUsername' ) == null ) {
98
- throw new RuntimeException ( " `-PhibernatePublishUsername=...` not found" )
90
+ for ( final def task in graph. allTasks ) {
91
+ if ( task instanceof PublishToMavenRepository ) {
92
+ if ( ossrhUsername == null ) {
93
+ throw new RuntimeException ( " OSSRH username not specified, but publishing was requested" )
99
94
}
100
- if ( project . property( ' hibernatePublishPassword ' ) == null ) {
101
- throw new RuntimeException ( " `-PhibernatePublishPassword=...` not found " )
95
+ if ( ossrhPassword == null ) {
96
+ throw new RuntimeException ( " OSSRH password not specified, but publishing was requested " )
102
97
}
103
-
104
- break ;
98
+ break
105
99
}
106
100
}
107
101
}
@@ -139,6 +133,3 @@ idea {
139
133
name = " hibernate-orm"
140
134
}
141
135
}
142
-
143
-
144
-
0 commit comments