forked from elig/Gradle-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
140 lines (123 loc) · 4.39 KB
/
build.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* There are 2 ways to activate the Artifactory Build-Info plugin.
* 1. use apply from directly from the build.gradle as shown below.
* 2. use the init script "gradle --init-script init.gradle" ATTENTION: Check the URL inside this init.gradle
* 3. Copy the init.gradle to your ~/.gradle directory and execute normally. ATTENTION: Now the Artifactory URL will
* always be applied to all your projects.
*
* Check the URL that apply uses to get the remote script
*
*/
buildscript {
repositories {
maven {
// url "http://repo.jfrog.org/artifactory/gradle"
url "http://repo-demo:8080/artifactory/gradle"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.12')
}
}
}
import java.text.DateFormat
import java.text.SimpleDateFormat
def globalVersion = new Version(currentVersion)
allprojects {
apply plugin: 'artifactory'
apply plugin: 'idea'
group = 'org.jfrog.example.gradle'
version = globalVersion
status = version.status
}
artifactoryPublish.skip=true
subprojects {
apply plugin: 'maven'
apply plugin: 'java'
dependencies {
testCompile 'junit:junit:4.7'
}
manifest.mainAttributes(provider: 'gradle')
configurations {
published
}
task sourceJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
task javadocJar(type: Jar, dependsOn:javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifactoryPublish {
dependsOn sourceJar,javadocJar
}
// Add the sourceJars to non-extractor modules
artifacts {
published sourceJar
published javadocJar
}
}
artifactory {
//contextUrl = 'http://repo.jfrog.org/artifactory'
contextUrl = 'http://repo-demo:8080/artifactory'
publish {
repository {
repoKey = 'gradle-snapshot-local' //The Artifactory repository key to publish to
username = "${artifactory_user}" //The publisher user name
password = "${artifactory_password}" //The publisher password
ivy {
//Optional section for configuring Ivy publication (when publishIvy = true). Assumes Maven repo layout if If not specified
ivyLayout = '[organization]/[module]/ivy-[revision].xml'
artifactLayout = '[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]'
mavenCompatible = false //Convert any dots in an [organization] layout value to path separators, similar to Maven's groupId-to-path conversion. True if not specified
}
}
defaults {
publishConfigs('archives','published')
properties = ['build.status': "$it.project.status".toString()]
publishPom = false //Publish generated POM files to Artifactory (true by default)
publishIvy = true //Publish generated Ivy descriptor files to Artifactory (true by default)
}
}
resolve {
repository {
repoKey = 'gradle' //The Artifactory (preferably virtual) repository key to resolve from
username = "${artifactory_user}" //Optional resolver user name (leave out to use anonymous resolution)
password = "${artifactory_password}" //The resolver password
}
}
}
dependsOnChildren()
task wrapper(type: Wrapper) {
gradleVersion = '1.0-milestone-8'
}
class Version {
String originalVersion
String thisVersion
String status
Date buildTime
Version(String versionValue) {
buildTime = new Date()
originalVersion = versionValue
if (originalVersion.endsWith('-SNAPSHOT')) {
status = 'integration'
thisVersion = originalVersion.substring(0, originalVersion.length() - 'SNAPSHOT'.length()) + getTimestamp()
} else {
status = 'release'
thisVersion = versionValue
}
}
String getTimestamp() {
// Convert local file timestamp to UTC
def format = new SimpleDateFormat('yyyyMMddHHmmss')
format.setCalendar(Calendar.getInstance(TimeZone.getTimeZone('UTC')));
return format.format(buildTime)
}
String toString() {
thisVersion
}
}