Files
airflow/java-sdk/example
Jason(Zhe-You) Liu a419633896 Java SDK: Rewrite the user docs around Dag definition (#74701)
* Java SDK: Rewrite the user docs around Dag definition

Reorder the Java SDK guide to start from a Dag defined in Java, document
conditions, switches and TriggerDagRun, and add a table of how stub task
arguments bind. Split the README into a user landing page and
DEVELOPMENT.md, and add an example README.

* Add Logback and appender to the docs spelling wordlist

* Address review: Dag-level queue, version sync, dropped constraints

Set the queue once on the Dag in every example, now that a Java Dag takes
one, and bump the documented version to 1.0.0-beta2 everywhere. Add a prek
hook that fails when the guide, the README and the Dokka landing page name
different versions. Restore the TaskInput constraints, correct the
LocalExecutor wording, and drop the Python Label comparison.

* Generate the quick start of the Java SDK README and Dokka page

The quick start appears on three pages. The guide owns it now, between
SHARED SNIPPET markers, and the sync-java-sdk-docs hook copies it into the
other two and still checks that all three install the same version.

* Address review: install a version placeholder, not a release

The three pages that show how to install the SDK pinned a release that is
not out yet, which also held the PR back. They now install `<version>` and
link to Maven Central, and the sync hook fails when a page names a release
instead. The parse-failure bullet leads with the SDK release a JAR was built
with, and keeps the supervisor schema version as the explanation.

---------
2026-10-23 12:18:53 +08:00
..

Java SDK examples

Example Dags for the Apache Airflow Java SDK. See the Java SDK guide for the full documentation.

Build

Publish the SDK to the local Maven repository, then build the example bundle into build/bundle/:

cd java-sdk
./gradlew publishToMavenLocal -PskipSigning=true

cd example
../gradlew bundle

Configure Airflow

Register build/bundle/ as a Dag bundle, and route the java queue to the Java coordinator:

export AIRFLOW__DAG_PROCESSOR__DAG_BUNDLE_CONFIG_LIST='[
  {"name": "dags-folder", "classpath": "airflow.dag_processing.bundles.local.LocalDagBundle", "kwargs": {}},
  {
    "name": "java-task-handlers",
    "classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
    "kwargs": {"path": "/absolute/path/to/airflow/java-sdk/example/build/bundle"}
  }
]'
export AIRFLOW__SDK__COORDINATORS='{
  "java": {
    "classpath": "airflow.sdk.coordinators.java.JavaCoordinator",
    "kwargs": {"task_handler_bundle_name": "java-task-handlers"}
  }
}'
export AIRFLOW__SDK__QUEUE_TO_COORDINATOR='{"java": "java"}'

The workers and the Dag processor need Java 11 or later on PATH.

Dag definition

These Dags are declared entirely in Java, in src/java/org/apache/airflow/example/nativedag/:

Dag Source Shows
java_native_annotation_example AnnotationExample.java The annotation style: task inputs, a task group, @Airflow.If, @Airflow.Switch, and TriggerDagRun
java_native_interface_example InterfaceExample.java A similar Dag in the interface style, with DagDef
java_native_target_example TargetExample.java The Dag the other two trigger
airflow dags trigger java_native_annotation_example
airflow dags trigger java_native_interface_example

Python Dag with stub TaskHandler

These Dags are declared in Python, in src/resources/dags/java_examples.py, and their stub tasks are implemented in Java:

Dag Source Shows
java_annotation_example AnnotationExample.java @Airflow.TaskHandler methods, with arguments by position and by name
java_interface_example InterfaceExampleBuilder.java Task and InputTask classes registered by Dag and task id
java_xcom_casting_example XComCastingExample.java How values passed between tasks convert to the declared Java types

Copy src/resources/dags/java_examples.py into your Airflow Dags folder, and create the Connection and Variable the examples read:

export AIRFLOW_CONN_TEST_HTTP='{
    "conn_type": "http",
    "login": "user",
    "password": "pass",
    "host": "example.com",
    "port": 1234,
    "extra": {"param1": "val1", "param2": "val2"}
}'
export AIRFLOW_VAR_MY_VARIABLE=123
airflow dags trigger java_annotation_example
airflow dags trigger java_interface_example
airflow dags trigger java_xcom_casting_example