-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
230 lines (201 loc) · 9.46 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
plugins {
id "java-library"
id "eclipse"
id "edu.wpi.first.GradleRIO" version "2024.3.2"
id "org.ajoberstar.grgit" version "3.0.0"
id "maven-publish"
id "io.github.mosadie.vendorJSON" version "1.0"
}
group = archivesGroup
// Sets JDK compatibility to JDK 17
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
// Configuration for build task which compiles , generates the javadoc and does the install
// of 3128-common in local maven cache.
// Also used by Jitpack/GitHub Actions.
if (System.getProperty("local")) {
println("This is a local Compile:")
version = "local"
}
else {
println("This is a versioned Compile:")
version = LibraryVersion
}
// Version identifier used for local maven cache and github releases.
// Should stay as "local". This allows the robot* projects on the
// same PC as 3128-common to pull from the local cache with the fixed
// version name "local" and so always be pointing at the current 3128-common
// version including those under development and not have to be updated
// each time the 3128-common version changes. Release to the world via github
// is based on actual version numbers and 3128-common.json.
//
// When starting a new version you can update LibraryVersion.java,
// overview.html and gradle.properties. DO NOT update 3128-common.json. It is
// maintained by the release github action when you release with github.
//
// Build in Eclispe using the Build 3128-common or Build 3128-common (Offline)
// run configurations. You can push to github as much as you want.
//
// When ready to release, make sure the version number and dates are
// correct in the files named above then update README.md. Final push all of your
// changes to GitHub. Also check on github Actions tab if the latest commit has a
// checkmark, indicating GitHub was able to build the code successfully.
//
// Then on GitHub, create a new release. This will create the release
// and then GitHub Actions will be triggered to compile the project and
// add the generated files (artifacts) to the release. Additionally, the release
// will become available from the Jitpack.io repository. Note that
// the IF statement above detects when gradle is running on GitHub Actions
// and sets the version varible to the actual version number (instead
// of "local") when compiling for release. The release action will update
// robolib.json to the new version on github. After release action is complete
// you can fetch from github with tags to get the updated 3128-common.json and
// release tag back into the local git repo.
//
// When all this is done, other user's robot projects that want the updated
// 3128-common, edit their local 3128-common.json to reflect the new version number
// and on next compile, gradle will pull the new library to their PC.
//
// Or if using VSCode, run the Manage Vendor Libraries (online) command and
// it will detect the new 3128-common version and offer to update the VSCode project.
//
// Warning: The github release action only works on the master branch. Do not
// create releases from other branches.
//
// Note: the github action files gradleCI.yml and gradleRelease.yml are
// located in .github\workflows.
//
println("LibraryVersion=" + LibraryVersion + "; compile version=" + version)
// Currently does not work
// This task updates the vendor json file for this project to the specified version.
vendorJSON {
fileName = jsonFileName
version = LibraryVersion
addJavaArtifact(archivesGroup, archivesBaseName, LibraryVersion)
}
// This section is to prevent people from accidently deploying this project to a robot.
// deploy {
// for (String task : project.gradle.startParameter.taskNames) {
// if (task == "deploy")
// throw new GradleException("This is a library project! You can't deploy it to a robot!")
// }
// }
// Generates Source and Javadoc jars when building.
java {
withJavadocJar();
withSourcesJar();
}
// Look in local maven cache first, then maven central for dependent libraries.
repositories {
// This is needed to fix problem with the url below redirecting to an http (insecure) url.
//maven {
// url "https://www.revrobotics.com/content/sw/color-sensor-v3/sdk/maven/"
// allowInsecureProtocol = true
//}
mavenLocal()
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/Mechanical-Advantage/AdvantageKit")
credentials {
username = "Mechanical-Advantage-Bot"
password = "\u0067\u0068\u0070\u005f\u006e\u0056\u0051\u006a\u0055\u004f\u004c\u0061\u0079\u0066\u006e\u0078\u006e\u0037\u0051\u0049\u0054\u0042\u0032\u004c\u004a\u006d\u0055\u0070\u0073\u0031\u006d\u0037\u004c\u005a\u0030\u0076\u0062\u0070\u0063\u0051"
}
}
}
// Setup eclipse classpath settings, so the javadoc and sources are available in eclipse
eclipse {
classpath {
downloadJavadoc = true
downloadSources = true
}
}
// task(checkAkitInstall, dependsOn: "classes", type: JavaExec) {
// mainClass = "org.littletonrobotics.junction.CheckInstall"
// classpath = sourceSets.main.runtimeClasspath
// }
// compileJava.finalizedBy checkAkitInstall
// Defining dependencies. In this case, WPILib (+ friends), and some vendor libraries (NavX, CTRE)
dependencies {
implementation wpi.java.deps.wpilib()
implementation wpi.java.vendor.java()
implementation group: 'gov.nist.math', name: 'jama', version: '1.0.3'
implementation 'org.java-websocket:Java-WebSocket:1.4.1'
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
def akitJson = new groovy.json.JsonSlurper().parseText(new File(projectDir.getAbsolutePath() + "/vendordeps/AdvantageKit.json").text)
annotationProcessor "org.littletonrobotics.akit.junction:junction-autolog:$akitJson.version"
// For reference, here are a few more of the easy to add libraries not currently used:
//implementation pathfinder() (Jaci's)
//implementation openrioMatchData()
// Quick guide to keywords:
// api is for libraries that are expected to be needed in the main robot project.
// implementation is for libraries that will not be needed in the main robot project.
// (Both api and implementation keywords will have the library automatically downloaded with 3128-common)
// compileOnly expects the dependency to be provided somewhere else. (Ex. by a main robot project)
// compile means include in the output library jar (see below).
}
// These next definitions (branch and hash) attempt to find extra information to add to the the manifest of
// the robot program jar file.
// Returns either the name of the current branch, or an empty string if no git repo is found.
def branch = { ->
if (grgit == null) { // If there's no git repo.
return ""
}
return grgit.branch.current().getName()
}
// Returns either the short hash of the last commit or an empty string if no git repo is found.
def hash = { ->
if (grgit == null) { // If there's no git repo.
return ""
}
return grgit.head().abbreviatedId
}
// Setting up 3128-common Jar File. In this case, adding version information to jar manifest.
jar {
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes("LibraryVersion": LibraryVersion) // from gradle.properties file.
attributes("Time": new Date().format("yyyy-MM-dd HH:mm:ss"))
attributes("User": System.getProperty("user.name"))
attributes("Branch": branch())
attributes("Commit": hash())
}
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
// Create Sources Jar
//task sourcesJar(type: Jar, dependsOn: classes) {
// classifier = 'sources'
// from sourceSets.main.allSource
//}
// When Javadoc is created (./gradlew.bat javadoc) it will be in this directory in the project folder.
javadoc {
destinationDir = file("doc")
title = "3128-common"
options.overview = "src/main/resources/overview.html"
// These options obsolete with move to JDK 17.
//options.addBooleanOption "-no-module-directories", true
//options.addBooleanOption "-frames", true
// This option supresses all Javadoc warnings. Some warnings are usefull but many
// we ignore. Should review warnings with any significant changes to the library.
options.addStringOption('Xdoclint:all,-missing', '-quiet')
}
// Create Javadoc Jar
//task javadocJar(type: Jar, dependsOn: javadoc) {
// classifier = 'javadoc'
// from javadoc.destinationDir
//}
// Additional artifacts to publish for JitPack
artifacts {
archives sourcesJar
archives javadocJar
}
// Required as of gradle 7.1.1. Configures PublishToMavenLocal task. This task is required to get our
// jars published to the local maven repository on this PC for consumption by robot projects on this PC.
// The PubishToMavenLocal task is executed in the eclipse .launch files that run this build.
publishing {
publications {
common(MavenPublication) {
artifactId = '3128-common'
from components.java
}
}
}