Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ js:
- "**/package.json"
- "js/**"

java:
- changed-files:
- any-glob-to-any-file:
- "**/*.java"
- "**/pom.xml"
- "java/**"

tooling:
- changed-files:
- any-glob-to-any-file:
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

name: Java tests and checks

on:
pull_request:
paths:
- "java/**"
- "genkit-tools/**"
- ".github/workflows/java.yml"

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java-version: ['17', '21']
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
cache: 'maven'

- name: Build with Maven
run: mvn -B clean compile -q
working-directory: ./java

- name: Run tests
run: mvn -B test
working-directory: ./java

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'

- name: Check code formatting with Spotless
run: mvn -B spotless:check
working-directory: ./java

- name: Run Checkstyle
run: mvn -B checkstyle:check
working-directory: ./java
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,17 @@ next-env.d.ts
# Code Coverage
js/plugins/compat-oai/coverage/

# Java
java/**/target/
java/**/*.class
java/**/*.jar
java/**/*.war
java/**/*.ear
java/**/.classpath
java/**/.project
java/**/.settings/
java/**/*.iml
java/**/.genkit
*.log
hs_err_pid*
java/samples/google-genai/generated_media/
16 changes: 15 additions & 1 deletion genkit-tools/common/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ export async function findProjectRoot(): Promise<string> {
const goModPath = path.join(currentDir, 'go.mod');
const pyprojectPath = path.join(currentDir, 'pyproject.toml');
const pyproject2Path = path.join(currentDir, 'requirements.txt');
const javaPomPath = path.join(currentDir, 'pom.xml');
const javaBuildGradlePath = path.join(currentDir, 'build.gradle');

try {
const [
packageJsonExists,
goModExists,
pyprojectExists,
pyproject2Exists,
javaPomExists,
javaBuildGradleExists,
] = await Promise.all([
fs
.access(packageJsonPath)
Expand All @@ -61,12 +65,22 @@ export async function findProjectRoot(): Promise<string> {
.access(pyproject2Path)
.then(() => true)
.catch(() => false),
fs
.access(javaPomPath)
.then(() => true)
.catch(() => false),
fs
.access(javaBuildGradlePath)
.then(() => true)
.catch(() => false),
]);
if (
packageJsonExists ||
goModExists ||
pyprojectExists ||
pyproject2Exists
pyproject2Exists ||
javaPomExists ||
javaBuildGradleExists
) {
return currentDir;
}
Expand Down
Loading
Loading