com.airbnb.viaduct.application-gradle-plugin) is applied to the root project of a Viaduct application. It orchestrates schema assembly from all modules, generates GRT (Generated Runtime Types) classes, and provides development tools.
Overview
The application plugin provides:- Central schema assembly - Combines schema partitions from all modules
- GRT (Generated Runtime Types) generation - Generates type-safe GraphQL object classes
- Development server - GraphiQL IDE for local development (
servetask) - Scaffolding - Project setup utilities (
scaffoldtask) - Schema validation - Build-time schema validation
- Distribution - Packages GRT JAR with central schema
Installation
In rootbuild.gradle.kts:
Extension
viaductApplication
Configuration extension for application-level settings.Properties
Package name for generated GRT (Generated Runtime Types) classes.Example:
"com.example.myapp"Effect: All generated type classes will be in this packageOptional package prefix for modules. Used by the development server to discover modules.Example:
"com.example.myapp"Default: Empty (scans all packages)Port for the development server.Default:
8080Override at runtime:Host for the development server.Default:
"localhost"Override at runtime:Tasks
assembleViaductCentralSchema
Combines schema partitions from all modules into a central schema. Type:AssembleCentralSchemaTask
Input:
- Schema partitions from all module plugins
- Optional base schema from
src/main/viaduct/schemabase/ - Optional common schema from
src/viaduct/schema/
- Central schema directory in
build/viaduct-central-schema/
Schema partitions from all module plugins (automatically configured)
Application-wide base schema files from
src/main/viaduct/schemabase/Use for:- Custom directives
- Application-wide types
- Shared interfaces
Root-level schema extensions from
src/viaduct/schema/Use for:- Global Query/Mutation extensions
- Cross-module fields
Output directory for the assembled central schema
generateViaductGRTs
Generates GRT (Generated Runtime Types) classes and packages them with the central schema. Type:Jar
Input:
- Central schema from
assembleViaductCentralSchema
- JAR file:
build/libs/viaduct-grt.jar
- Generated type classes (
.classfiles) - Central schema GraphQL files (in
viaduct/centralSchema/)
- Object types -
User,Post,Comment - Input types -
CreateUserInput,UpdatePostInput - Enums -
Role,Status - Interfaces -
Node,Timestamped - Arguments -
UserQueryArguments,PostsConnectionArguments - Reflection types -
User.Reflection,Post.Reflection - Builders -
User.Builder,Post.Builder
serve
Starts the Viaduct development server with GraphiQL IDE. Type:JavaExec
Features:
- GraphiQL web interface for testing queries
- Automatic schema discovery from modules
- Hot reload with
--continuousflag - CORS enabled for local development
- WebSocket support for subscriptions
http://localhost:8080/graphiql to access:
- Query editor with syntax highlighting
- Schema documentation browser
- Query history
- Variable editor
- Response viewer
- Ktor server (Netty)
- Content negotiation (Jackson)
- CORS support
- WebSocket support
- Your application classes and dependencies
Port to bind (default: 8080)
Host to bind (default: localhost)
Package prefix for module discovery (from
modulePackagePrefix)scaffold
Generates a new Viaduct project structure with example code. Type:ScaffoldTask
Usage:
Base package name for generated codeDefault:
"com.example.myapp"Example: "com.mycompany.api"Output directory for scaffolded projectDefault:
"scaffold-output"Gradle version for the scaffolded projectDefault: Latest stable
Configurations
allSchemaPartitionsIncoming
Type: Resolvable configuration Purpose: Receives schema partitions from all module plugins Attributes:viaductKind = SCHEMA_PARTITION
centralSchemaOutgoing
Type: Consumable configuration Purpose: Provides the central schema to module plugins (for resolver generation) Artifacts:- Output directory of
assembleViaductCentralSchema
grtClassesOutgoing
Type: Consumable configuration Purpose: Provides GRT JAR to module plugins Attributes:viaductKind = GRT_CLASSESusage = JAVA_RUNTIMEcategory = LIBRARYlibraryElements = JAR
viaduct-grt.jarfromgenerateViaductGRTs
Schema Locations
Base Schema (src/main/viaduct/schemabase/)
Application-wide schema definitions that apply to all modules.
Use for:
- Custom directives
- Shared interfaces
- Common types
- Application-specific scalars
Common Schema (src/viaduct/schema/)
Root-level Query/Mutation/Subscription extensions.
Use for:
- Global fields that don’t belong to a specific module
- Cross-module aggregations
Development Workflow
Initial Setup
Making Schema Changes
Build for Production
Best Practices
Do
- Use
--continuous servefor development - Automatic reload on changes - Set meaningful package names - Use your organization’s package structure
- Keep base schema minimal - Only truly global definitions
- Version control generated GRT JAR - Optional but useful for CI/CD
- Use GraphiQL for testing - Faster than external tools
Don’t
- Don’t apply to non-root projects - Only root project should use this plugin
- Don’t modify generated GRT classes - They’re regenerated on every build
- Don’t commit
build/directory - Except optionally the GRT JAR - Don’t skip schema validation - Run full build before deploying
Troubleshooting
GRT classes not found
Solution:Schema changes not reflected in serve
Solution: Use--continuous flag:
Module schemas not included
Solution: Ensure modules:- Apply the module plugin
- Are included in
settings.gradle.kts - Have schema files in
src/main/viaduct/schema/
Port already in use
Solution:See Also
- Module Plugin - Plugin for individual modules
- Service API - Integrating Viaduct into your service
- Tenant API - Writing resolvers
- Directives - Schema directives