File: publish.gradle

package info (click to toggle)
groovy 2.4.21-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 30,708 kB
  • sloc: java: 157,114; xml: 728; sh: 357; makefile: 64; javascript: 15
file content (113 lines) | stat: -rw-r--r-- 5,734 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */
import org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact

ext.artifactoryUser = project.hasProperty('artifactoryUser') ? project.artifactoryUser : System.getenv('ARTIFACTORY_USER')
ext.artifactoryPassword = project.hasProperty('artifactoryPassword') ? project.artifactoryPassword : System.getenv('ARTIFACTORY_PASSWORD')

if (!artifactoryUser) {
    // try to read artifactory.properties
    def base = file(projectDir)
    def artifactoryFile = new File(base, 'artifactory.properties')
    while (!artifactoryFile.exists()) {
        base = base.parentFile
        if (!base) break
        artifactoryFile = new File(base, 'artifactory.properties')
    }
    if (artifactoryFile.exists()) {
        logger.lifecycle 'Found artifactory.properties in ' + base.path
        def props = new Properties()
        props.load(artifactoryFile.newReader())
        ext.artifactoryUser = props.getProperty('artifactoryUser','')
        ext.artifactoryPassword = props.getProperty('artifactoryPassword','')
    } else {
        logger.lifecycle 'No artifactory.properties file found'
    }
}

allprojects {
    if (project == rootProject || rootProject.ext.modules().contains(project)) {
        apply plugin: 'com.jfrog.artifactory-upload'

        artifactory {
            contextUrl = project.hasProperty('artifactoryContext') ? project.artifactoryContext : 'https://oss.jfrog.org'
            resolve {
                repository {
                    repoKey = 'libs-release'
                }
            }
            publish {
                excludePatterns = "org/codehaus/groovy/groovy/*/groovy-all-*,org/codehaus/groovy/groovy/*/groovy-bom-*,org/codehaus/groovy/groovy/*/groovy-backports-*,org/codehaus/groovy/groovy/*/groovy-binary-*"
                repository {
                    repoKey = project.hasProperty('artifactoryRepoKey') ? project.artifactoryRepoKey : 'oss-snapshot-local'
                    //The Artifactory repository key to publish to
                    //when using oss.jfrog.org the credentials are from Bintray. For local build we expect them to be found in
                    //~/.gradle/gradle.properties, otherwise to be set in the build server
                    username = rootProject.artifactoryUser
                    password = rootProject.artifactoryPassword
                }
            }
        }
    }
}

artifactoryPublish {
    def curDate = new Date()
    def pomSource = { a -> "$projectDir/target/poms/pom-${a.name - 'groovy-'}.xml" }
    def destBase = { a -> "org/codehaus/groovy/${a.name}/${version}/${a.name}-${version}${a.classifier ? '-' + a.classifier : ''}" }
    def newDetails = { orig, newFile, newExt, newType -> gradleDeployDetails(new DefaultPublishArtifact(
            orig.name, newExt, newType, orig.classifier, curDate, newFile), 'artifacts', destBase(orig) + '.' + newExt) }
    def makeTransformedDetails = { orig -> newDetails(orig, orig.file, orig.extension, orig.extension) }
    def makeTransformedPomDetails = { orig -> newDetails(orig, file(pomSource(orig)), 'pom', 'pom') }
    def makeTransformedPomSigDetails = { orig -> newDetails(orig, file(pomSource(orig) + '.asc'), 'pom.asc', 'asc') }
    mavenDescriptor = new File("$projectDir/target/poms/pom-groovy.xml")
    doFirst{
        configurations.archives.artifacts.findAll{ it.name != project.name }.each {
            // the plugin we are using uses the project name rather than the artifact name
            // as the artifactId, so we add the transformed one ourselves
            // this also covers signatures which we already added during install
            deployDetails.add(makeTransformedDetails(it))
            if (!it.classifier && (it.type == 'jar' || it.type == 'zip')) {
                // add the pom and its signature
                deployDetails.add(makeTransformedPomDetails(it))
                if (isReleaseVersion) {
                    deployDetails.add(makeTransformedPomSigDetails(it))
                }
            }
        }
        deployDetails.add(makeTransformedPomDetails(name: 'groovy-bom'))

        if (isReleaseVersion) {
            deployDetails.add(makeTransformedPomSigDetails(name: 'groovy-bom'))
            allprojects {
                if (project == rootProject || rootProject.ext.modules().contains(project)) {
                    configurations.archives.artifacts.findAll {
                        it.name == project.name && it.type == 'jar' && it.extension == 'jar' && !it.classifier
                    }.each {
                        // add pom signatures
                        def pomSigLocation = "$project.projectDir/target/poms/pom-${project == rootProject ? 'groovy' : 'default'}.xml.asc"
                        deployDetails.add(newDetails(it, file(pomSigLocation), 'pom.asc', 'pom'))
                    }
                }
            }
        }
    }
}

artifactoryPublish.dependsOn('backportJars')