Files
allwpilib/shared/java/javacommon.gradle
Peter Johnson cf54d9ccb7 [wpiutil, ntcore] Add structured data support (#5391)
This adds support for two serialization formats for complex data types:

- Protobuf for complex objects with variable length internals that need forward and backward wire compatibility (lower speed, more flexible)
- Raw struct (ByteBuffer-style) for fixed-length objects (higher speed, less flexible)

Deserialization can be done either by creating a new object (for immutable objects) or overwriting the contents of an existing object (for mutable objects).

Implementing classes should provide inner classes that implement the Protobuf or Struct interface (in Java) or specialize the wpi::Protobuf or wpi::Struct struct (in C++). It is possible for classes to implement both. If the class itself does not implement serialization, it's possible for third parties/users to provide an implementation instead.

Uses the Google protobuf implementation for C++ and the QuickBuffers alternative protobuf implementation for Java.
2023-10-19 21:41:47 -07:00

169 lines
3.8 KiB
Groovy

apply plugin: 'maven-publish'
apply plugin: 'java-library'
apply plugin: 'jacoco'
apply plugin: 'com.google.protobuf'
def baseArtifactId = project.baseId
def artifactGroupId = project.groupId
def javaBaseName = "_GROUP_edu_wpi_first_${project.baseId}_ID_${project.baseId}-java_CLS"
def outputsFolder = file("$project.buildDir/outputs")
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
task outputJar(type: Jar, dependsOn: classes) {
archiveBaseName = javaBaseName
destinationDirectory = outputsFolder
from sourceSets.main.output
}
task outputSourcesJar(type: Jar, dependsOn: classes) {
archiveBaseName = javaBaseName
destinationDirectory = outputsFolder
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
task outputJavadocJar(type: Jar, dependsOn: javadoc) {
archiveBaseName = javaBaseName
destinationDirectory = outputsFolder
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
archives outputJar
archives outputSourcesJar
archives outputJavadocJar
}
addTaskToCopyAllOutputs(outputSourcesJar)
addTaskToCopyAllOutputs(outputJavadocJar)
addTaskToCopyAllOutputs(outputJar)
build.dependsOn outputSourcesJar
build.dependsOn outputJavadocJar
build.dependsOn outputJar
project(':').libraryBuild.dependsOn build
publishing {
publications {
java(MavenPublication) {
artifact jar
artifact sourcesJar
artifact javadocJar
artifactId = "${baseArtifactId}-java"
groupId artifactGroupId
version wpilibVersioning.version.get()
}
}
}
test {
useJUnitPlatform()
systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'
testLogging {
events "failed"
exceptionFormat "full"
}
finalizedBy jacocoTestReport
}
if (project.hasProperty('onlylinuxathena') || project.hasProperty('onlylinuxarm32') || project.hasProperty('onlylinuxarm64') || project.hasProperty('onlywindowsarm64')) {
test.enabled = false
}
repositories {
maven {
url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
}
//maven.url "https://oss.sonatype.org/content/repositories/snapshots/"
}
sourceSets {
dev
}
configurations {
devImplementation.extendsFrom(implementation)
}
tasks.withType(JavaCompile).configureEach {
options.compilerArgs = [
'--release',
'11',
'-encoding',
'UTF8',
"-Werror",
"-Xlint:all",
// ignore AutoCloseable warnings
"-Xlint:-try",
// ignore missing serialVersionUID warnings
"-Xlint:-serial",
]
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
devImplementation sourceSets.main.output
}
task run(type: JavaExec) {
classpath = sourceSets.dev.runtimeClasspath
mainClass = project.devMain
}
build.dependsOn devClasses
jacoco {
toolVersion = "0.8.10"
}
jacocoTestReport {
reports {
xml.required = true
html.required = true
}
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.21.12'
}
plugins {
quickbuf {
artifact = 'us.hebi.quickbuf:protoc-gen-quickbuf:1.3.2'
}
}
generateProtoTasks {
all().configureEach { task ->
task.builtins {
cpp {}
remove java
}
task.plugins {
quickbuf {
option "gen_descriptors=true"
}
}
}
}
}