Install protoc v25.1
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v25.1/protoc-25.1-linux-x86_64.zip
unzip protoc-25.1-linux-x86_64.zip -d $HOME/.local
export PATH="$PATH:$HOME/.local/bin"
The follow command should output v25.1
:
protoc --version
<!-- bazel build //... -->
bazel build :protos_java
Delete generated folder:
rm -rf generated
- Run the provided script to generate Java files from proto files:
./tools/java/generate_java.sh
This script will:
- Build the Java proto library using Bazel
- Find all source JAR files containing generated Java code
- Extract the Java files to the
generated/java
directory
- You can find the generated Java files in the
generated/java
directory:
find generated/java -name "*.java" | sort
To package the generated Java files into a Maven-compatible JAR that can be used as a Gradle dependency:
- Run the provided script:
./tools/java/package_proto_jar.sh
This script will:
- Generate Java files from proto files (if not already done)
- Download the protobuf-java dependency
- Compile the Java files
- Create a Maven-compatible JAR file
- Install the JAR to your local Maven repository
- To use the JAR in a Gradle project, add the following to your build.gradle:
repositories {
mavenLocal()
}
dependencies {
implementation 'org.opensearch.protobuf:opensearch-protobuf:1.0.0'
}
All generated files are excluded from version control via the .gitignore
file. This includes:
- Bazel generated files (bazel-*)
- Generated files (generated/)
- Compiled class files (*.class)
- Package files (*.jar)