forked from INDExOS/media-for-mobile
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathartifactory.gradle
89 lines (74 loc) · 3.66 KB
/
artifactory.gradle
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
if (rootProject.plugins.hasPlugin("com.jfrog.artifactory") && getBuildProperty('ARTIFACTORY_PUBLISH_USERNAME')) {
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
//Workaround for strange init error "Cannot invoke method invoke() on null object"
def contextUrlTmp = getBuildProperty('ARTIFACTORY_CONTEXT_URL')
//By default we publish snapshots, if you want publish release
//please set env variable or gradle -P argument with PUBLISH_RELEASE=true
def publishRelease = getBuildProperty('PUBLISH_RELEASE', 'false').toBoolean()
def repoKeyTmp = publishRelease ?
getBuildProperty('ARTIFACTORY_REPO_KEY') :
getBuildProperty('ARTIFACTORY_SNAPSHOTS_REPO_KEY')
def usernameTmp = getBuildProperty('ARTIFACTORY_PUBLISH_USERNAME')
def passwordTmp = getBuildProperty('ARTIFACTORY_PUBLISH_PASSWORD')
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}
publishing {
publications {
aar(MavenPublication) {
artifact "$project.buildDir/outputs/aar/${project.getName()}-release.aar"
artifact androidSourcesJar
groupId project.group
version project.version + (publishRelease ? "" : "-SNAPSHOT")
artifactId project.getName()
//Add dependencies from android project configurations
//for java project you can use just `from configurations.java`
//But android project even more complex
//and maven-publish don't know nothing about android projects
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones),
//adding a <dependency> node for each
configurations.compile.allDependencies.each {
if (it.group != null && it.name != null) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
//If there are any exclusions in dependency
if (it.excludeRules.size() > 0) {
def exclusionsNode = dependencyNode.appendNode('exclusions')
it.excludeRules.each { rule ->
def exclusionNode = exclusionsNode.appendNode('exclusion')
exclusionNode.appendNode('groupId', rule.group)
exclusionNode.appendNode('artifactId', rule.module)
}
}
}
}
}
}
}
}
artifactory {
contextUrl = contextUrlTmp
publish {
repository {
repoKey = repoKeyTmp
username = usernameTmp
password = passwordTmp
maven = true
}
}
}
artifactoryPublish {
publications('aar')
}
artifactoryPublish.dependsOn('clean', 'generatePomFileForAarPublication', 'androidSourcesJar', 'assembleRelease')
publish.dependsOn artifactoryPublish
artifactoryPublish.mustRunAfter('clean')
} else {
logger.lifecycle(":${project.name} ARTIFACTORY_PUBLISH_USERNAME is empty, skip publish plugin init")
}