@@ -8,6 +8,7 @@ buildscript {
88
99plugins {
1010 id ' base'
11+ id ' maven-publish'
1112 // id 'com.github.hierynomus.license-report' version '0.15.0'
1213 // id 'com.github.spotbugs' version '4.7.6'
1314}
@@ -46,17 +47,23 @@ private void initialize() {
4647 }
4748}
4849
49- private String getOurArchivesBaseName ()
50- {
50+ private String getOurArchivesBaseName () {
5151 String val = String . valueOf(" ${ ext.ourArchivesBaseName} " )
5252 if (val. isEmpty() || val == ' null' )
5353 throw new InvalidUserDataException (' String is empty.' )
5454
5555 return " ${ val} "
5656}
5757
58- private void configureSigning (def android , File keystorePropsFile )
59- {
58+ private String getGitCommitHash () {
59+ try {
60+ return ' git rev-parse --short=8 HEAD' . execute(). text. trim()
61+ } catch (Exception ignored) {
62+ return " unknown"
63+ }
64+ }
65+
66+ private void configureSigning (def android , File keystorePropsFile ) {
6067 if (! keystorePropsFile. exists()) return
6168 if (android == null ) throw new GradleException (' android is null inside configureSigning()' )
6269
@@ -143,16 +150,15 @@ tasks.register('buildOtaOSS', Exec) {
143150 }
144151}
145152
146- tasks. named(' build ' ) {
153+ tasks. named(' assemble ' ) {
147154 group = null
148155 description = ' Alias of "buildOtaOSS" task.'
149156 finalizedBy buildOtaOSS
150157}
151158
152- tasks. named(' assemble' ) {
153- enabled = false
159+ tasks. named(' build' ) {
154160 group = null
155- description = ' Dummy task.'
161+ description = ' Alias of "buildOtaOSS" task.'
156162}
157163
158164tasks. register(' installTest' , Exec ) {
@@ -173,19 +179,57 @@ tasks.register('test') {
173179 dependsOn installTest
174180}
175181
176- tasks. named(' check' ) {
177- dependsOn ' test'
178- }
179-
180- // Dummy task
181- tasks. register(' install' ) {
182- enabled = false
183- group = null
184- description = ' Dummy task.'
185- }
186-
187182tasks. named(' wrapper' ). configure {
188183 println ' Gradle: ' + gradleVersionTarget
189184 gradleVersion = gradleVersionTarget
190185 distributionSha256Sum = gradleSha256Sum
191186}
187+
188+ /* === PUBLISHING === */
189+
190+ publishing {
191+ publications {
192+ maven(MavenPublication ) {
193+ artifactId = project. ext. ourArchivesBaseName
194+ pom {
195+ name = project. name
196+ packaging = ' zip'
197+ }
198+ }
199+ }
200+ }
201+
202+ tasks. withType(PublishToMavenLocal ). configureEach {
203+ // Ensure builds run before this task
204+ mustRunAfter ' build' , ' buildOta' , ' buildOtaOSS'
205+
206+ doFirst {
207+ def projectId = project. ext. ourArchivesBaseName
208+ def commit = getGitCommitHash()
209+ def zipFiles = fileTree(dir : project. buildDir). matching {
210+ include " ${ projectId} -${ version} -g${ commit} -*-by-ale5000-signed.zip"
211+ }. files
212+
213+ if (zipFiles. size() < 1 || zipFiles. size() > 2 ) {
214+ throw new GradleException (" Publishing failed: Expected 1 or 2 artifacts in '${ project.buildDir} ', but found ${ zipFiles.size()} . Check if build tasks were executed." )
215+ }
216+
217+ // Add artifacts to the publication just before execution
218+ def mavenPub = project. publishing. publications. maven
219+ zipFiles. each { foundFile ->
220+ def isFull = foundFile. name. contains(' -full-' )
221+ def isOss = foundFile. name. contains(' -oss-' )
222+
223+ if (! isFull && ! isOss) {
224+ throw new GradleException (" Publishing failed: File ${ foundFile.name} missing a valid build type." )
225+ }
226+
227+ mavenPub. artifact(foundFile) {
228+ if (isFull) {
229+ classifier = ' full'
230+ }
231+ extension = ' zip'
232+ }
233+ }
234+ }
235+ }
0 commit comments