This example demonstrates how to consume a Java library published to a OCI Registry.
- Consumes: A shared library (
io.seqera:shared-library:1.0.0) from Docker Hub - Registry: Docker Hub (registry-1.docker.io)
- Repository:
pditommaso/maven - Challenge: Standard Maven/Gradle don't natively support OCI registries
This example demonstrates the new mavenOci syntax for consuming libraries from OCI registries. The Maven OCI Registry Plugin now supports both publishing and consuming artifacts from OCI registries using standard Gradle dependency syntax.
The example references pditommaso/maven repository which must be created first by publishing artifacts. You have two options:
Run the publisher example first to create the repository:
cd ../publisher
export DOCKERHUB_USERNAME=pditommaso
export DOCKERHUB_PASSWORD=your-password
../../gradlew publishMavenPublicationToDockerhubRepositoryThis will:
- Create the
pditommaso/mavenrepository on Docker Hub - Push the JAR, POM, sources, and javadoc artifacts
- Make the repository available for consumption examples
You can test consumption patterns with any existing OCI repository by updating the artifact references in the code.
A service that translates Maven repository requests to OCI pulls:
repositories {
maven {
name = "OciMavenProxy"
url = uri("http://localhost:8080/maven")
// Proxy handles OCI resolution behind the scenes
}
}
dependencies {
implementation 'io.seqera:shared-library:1.0.0'
}A Gradle plugin that can resolve dependencies from OCI registries:
plugins {
id 'java'
id 'oci-resolver' // Hypothetical plugin
}
ociRepositories {
dockerHub {
url = 'https://registry-1.docker.io'
credentials {
username = project.findProperty('dockerHubUsername')
password = project.findProperty('dockerHubPassword')
}
}
}
dependencies {
implementation 'io.seqera:shared-library:1.0.0' // Resolves from mavenOci repository
}Use ORAS or Docker to manually extract artifacts:
# Pull the OCI artifact
docker pull pditommaso/maven:1.0.0
# Extract JAR files
docker run --rm -v $(pwd)/libs:/output pditommaso/maven:1.0.0 cp /*.jar /output/
# Add to local Maven repository
mvn install:install-file -Dfile=libs/shared-library-1.0.0.jar -DgroupId=io.seqera -DartifactId=shared-library -Dversion=1.0.0 -Dpackaging=jar# Build the consumer app
./gradlew build
# Run the consumer app
./gradlew run
# Show consumption information
./gradlew showConsumptionInfo
# Run tests
./gradlew test- Project Structure: How a consumer project would be organized
- Dependency Declaration: How dependencies would be declared (commented out for now)
- Usage Patterns: How the consumed library would be used
- Logging: Proper logging setup for the consumer application
This example is currently a placeholder that demonstrates:
- Project structure for consuming OCI artifacts
- Expected usage patterns
- Logging and testing setup
- Future integration possibilities
Once proper OCI artifact resolution is implemented (via proxy, plugin, or native support), this example can be updated to actually consume the published library.
- Publish: Use
../publisherto publish the shared library to Docker Hub - Consume: Use this consumer example to demonstrate consumption patterns
- Verify: Check that the complete publish-consume cycle works
- ORAS - OCI Registry as Storage
- Maven OCI Registry Plugin - Publisher side
- Docker Hub - OCI Registry