Skip to content

Commit 3165450

Browse files
committed
Initial commit
0 parents  commit 3165450

File tree

13 files changed

+586
-0
lines changed

13 files changed

+586
-0
lines changed

.github/workflows/build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Java CI with Gradle
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
build:
9+
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up JDK 21
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: '21'
20+
distribution: 'temurin'
21+
- name: Setup Gradle
22+
uses: gradle/actions/setup-gradle@v4
23+
- name: Build with Gradle Wrapper
24+
run: chmod +x gradlew && ./gradlew --no-daemon --stacktrace build

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.gradle
2+
build/
3+
!gradle/wrapper/gradle-wrapper.jar
4+
!**/src/main/**/build/
5+
!**/src/test/**/build/
6+
7+
### IntelliJ IDEA ###
8+
.idea
9+
*.iws
10+
*.iml
11+
*.ipr
12+
out/
13+
!**/src/main/**/out/
14+
!**/src/test/**/out/
15+
16+
### Eclipse ###
17+
.apt_generated
18+
.classpath
19+
.factorypath
20+
.project
21+
.settings
22+
.springBeans
23+
.sts4-cache
24+
bin/
25+
!**/src/main/**/bin/
26+
!**/src/test/**/bin/
27+
28+
### NetBeans ###
29+
/nbproject/private/
30+
/nbbuild/
31+
/dist/
32+
/nbdist/
33+
/.nb-gradle/
34+
35+
### VS Code ###
36+
.vscode/
37+
38+
### Mac OS ###
39+
.DS_Store

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Java JSpecify Example
2+
3+
Aa minimal Java project demonstrating the usage of `JSpecify` annotations, `NullAway`, and `Error Prone` static analysis tools.
4+
This project aims to showcase how to integrate and configure these tools in a Java project using `Gradle`.
5+
6+
---
7+
8+
### Usage
9+
10+
```bash
11+
git clone https://github.com/raharrison/java-jspecify-example.git
12+
cd java-jspecify-example
13+
./gradlew build
14+
```
15+
16+
### Notes
17+
18+
- The `UserRepo` class is annotated using `JSpecify`
19+
- By default, the build is set up to fail if any `NullAway` error is reported
20+
- Uncomment the line in `Main` to use a nullable object without a check beforehand. This will fail the build
21+
- `NullAway` will not run on test code
22+
- `NullAway` is configured to check all files in the specified project package. You can alternatively check only `NullMarked` code
23+
by annotating each class
24+
or through an annotated `package-info.java` file

build.gradle.kts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import net.ltgt.gradle.errorprone.errorprone
2+
3+
plugins {
4+
application
5+
id("java")
6+
id("com.gradleup.shadow") version "8.3.6"
7+
id("net.ltgt.errorprone") version "4.3.0"
8+
}
9+
10+
group = "com.example.myapp"
11+
version = "1.0-SNAPSHOT"
12+
13+
repositories {
14+
mavenCentral()
15+
}
16+
17+
dependencies {
18+
testImplementation(platform("org.junit:junit-bom:5.11.4"))
19+
testImplementation("org.junit.jupiter:junit-jupiter")
20+
21+
implementation("org.jspecify:jspecify:1.0.0")
22+
errorprone("com.google.errorprone:error_prone_core:2.40.0")
23+
errorprone("com.uber.nullaway:nullaway:0.12.7")
24+
}
25+
26+
tasks.test {
27+
useJUnitPlatform()
28+
}
29+
30+
java {
31+
toolchain {
32+
languageVersion = JavaLanguageVersion.of(21)
33+
}
34+
}
35+
36+
application {
37+
mainClass.set("com.example.myapp.Main")
38+
}
39+
40+
tasks.withType<JavaCompile> {
41+
options.errorprone {
42+
disableAllChecks = true
43+
option("NullAway:JSpecifyMode", "true")
44+
// option("NullAway:OnlyNullMarked", "true")
45+
option("NullAway:AnnotatedPackages", "com.example.myapp")
46+
error("NullAway")
47+
}
48+
// Disable NullAway on test code
49+
if (name.lowercase().contains("test")) {
50+
options.errorprone {
51+
disable("NullAway")
52+
}
53+
}
54+
}

gradle/wrapper/gradle-wrapper.jar

59.3 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

gradlew

Lines changed: 234 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)