-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.gradle
191 lines (164 loc) · 7.38 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
plugins {
id "com.gorylenko.gradle-git-properties" version "2.4.2"
}
description = "An IMC Java with bindings and generator for IMC."
defaultTasks 'dist', 'libsender'
ext {
distFolderName = "dist"
toolsFolderName = "tools"
automaticModuleNameBase = "pt.lsts.imc"
}
allprojects {
version = '5.90.4'
repositories {
mavenCentral()
}
apply plugin: 'java'
compileJava.options.encoding = 'UTF-8'
apply plugin: "com.gorylenko.gradle-git-properties"
sourceSets {
main {
java {
srcDirs = ['java']
}
resources {
srcDirs = ['resources']
}
}
}
processResources {
from (rootProject.projectDir) {
include 'COPYRIGHT.TXT'
}
doLast {
println 'Added common resources'
}
}
jar {
manifest {
attributes( 'Specification-Title': rootProject.name
,'Specification-Version': project.version
,'Implementation-Title': project.name
,'Implementation-Version': project.version
,'Build-Revision': "${rootProject.name}-${project.version}-git#${-> project.ext.gitProps['git.commit.id.describe']}"
,'Automatic-Module-Name': "${rootProject.ext.automaticModuleNameBase}.${project.name}"
,'Build-Jdk': System.properties['java.version']
)
}
}
gitProperties {
extProperty = 'gitProps'
failOnNoGitDirectory = false
dateFormat = "yyyy-MM-dd'T'HH:mmZ"
dateFormatTimeZone = "UTC"
gitPropertiesName = "git.info"
keys = ['git.branch',
'git.build.version',
'git.closest.tag.commit.count',
'git.closest.tag.name',
'git.commit.id',
'git.commit.id.abbrev',
'git.commit.id.describe',
'git.commit.time',
'git.dirty',
'git.remote.origin.url',
'git.tags',
]
}
generateGitProperties.outputs.upToDateWhen { false }
}
configure(subprojects.findAll { it.name != 'core' }) {
dependencies {
implementation project(':core')
implementation project(':core').sourceSets.main.runtimeClasspath
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
/**
* To add a net task to a project.
* @param proj the project object
* @param taskName the name of the task
* @param jarBaseName the archiveBaseName, use null for using the taskName instead
* @param destFolder the destination folder (relative to root folder, use null to use default
* @param mainClass the main class to add to the manifest, use null for none
* @param otherProjectsToPackToDistList other projects to add
* @param excludeCore to exclude adding the core libraries, you will needthem at runtime in the classpath
*
*/
def jarTask(proj, taskName, jarBaseName, destFolder, mainClass, otherProjectsToPackToDistList, excludeCore) {
configure(proj) {
proj.tasks.create(taskName, Jar) {
// Must be a better way to get the core jar here and filter out of the classpath for jar creation
dependsOn project(":core").getTasksByName("dist", true)
if (otherProjectsToPackToDistList != null)
dependsOn otherProjectsToPackToDistList.collect { it.jar }
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
description = "Generate ${jarBaseName ?: taskName} for IMC API"
group = 'Distribution'
manifest {m ->
m.getAttributes().put 'Specification-Title', rootProject.name
if (mainClass != null && !mainClass.isEmpty())
m.getAttributes().put 'Main-Class', mainClass
m.getAttributes().put 'Specification-Version', project.version
m.getAttributes().put 'Implementation-Title', "$project.name, ${jarBaseName ?: taskName}"
m.getAttributes().put 'Implementation-Version', project.version
m.getAttributes().put 'Build-Revision', "${rootProject.name}-${project.version}-git#${-> project.ext.gitProps['git.commit.id.describe']}"
m.getAttributes().put 'Automatic-Module-Name', "${rootProject.ext.automaticModuleNameBase}.$taskName"
m.getAttributes().put 'Build-Jdk', System.properties['java.version']
}
// Adding runtime jars into the jar
def addedAssets = configurations.runtimeClasspath - configurations.runtimeClasspath
if (otherProjectsToPackToDistList != null) {
otherProjectsToPackToDistList.collect { addedAssets += (it.sourceSets.main.runtimeClasspath - configurations.runtimeClasspath) }
addedAssets = addedAssets.findAll { !it.toString().contains(project.buildDir.toString()) }
}
// Adding runtime jars into the jar
def coreConf = configurations.runtimeClasspath - project(':core').sourceSets.main.runtimeClasspath
coreConf = coreConf.filter { File file ->
file.absolutePath ==~ "${project(':core').jar.archiveFile.get().getAsFile().getAbsolutePath().replaceAll('\\\\', '\\\\\\\\')}" ? false : true
}
from { coreConf.collect { it.isDirectory() ? it : zipTree(it).matching {
exclude "module-info.class"
} } }
if (!addedAssets.isEmpty())
from { addedAssets.toUnique().collect { it.isDirectory() ? it : zipTree(it).matching {
exclude "module-info.class"
} } }
if (excludeCore != null && !excludeCore)
from { zipTree(project(':core').dist.archivePath) }
with jar
archiveBaseName = jarBaseName ?: taskName
//archiveVersion = ''
destinationDirectory = file(destFolder != null && !destFolder.isEmpty() ? "$rootDir/$destFolder" : "$rootDir/$distFolderName")
doLast {
// println "$project.name"
// println project(':core').dist.archivePath
// println project(':core').jar.archivePath
// project(':core').sourceSets.main.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }.each { print ' >> '; println it }
// project(':core').configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }.each { print ' |> '; println it }
// println "configurations.runtimeClasspath"
// coreConf.collect { it.isDirectory() ? it : zipTree(it) }.each { print ' > '; println it }
// println "addedAssets"
// if (!addedAssets.isEmpty())
// addedAssets.toUnique().collect { it.isDirectory() ? it : zipTree(it) }.each { print ' > '; println it }
}
}
}
}
clean {
delete fileTree(dir: "$distFolderName" , include: '**/*.jar')
}
task cleanEclipseFiles {
delete fileTree(dir: "$rootDir" , include: '**/.project')
delete fileTree(dir: "$rootDir" , include: '**/.classpath')
delete fileTree(dir: "$rootDir" , include: '**/.settings')
}
task cleanIdeaFiles {
delete fileTree(dir: "$rootDir" , include: '**/.idea')
}
task cleanVSCodeFiles {
delete fileTree(dir: "$rootDir" , include: '.vscode')
}