Skip to content

1. Installation

dzikoysk edited this page Aug 22, 2024 · 25 revisions

Gradle

Gradle (Kts) setup for Javalin 6.x

repositories {
    // For snapshots
    maven("https://maven.reposilite.com/snapshots")
}

dependencies {
    val openapi = "6.3.0"
    
    // For Java projects
    annotationProcessor("io.javalin.community.openapi:openapi-annotation-processor:$openapi")
    // For Kotlin projects
    kapt("io.javalin.community.openapi:openapi-annotation-processor:$openapi")

    implementation("io.javalin.community.openapi:javalin-openapi-plugin:$openapi") // for /openapi route with JSON scheme
    implementation("io.javalin.community.openapi:javalin-swagger-plugin:$openapi") // for Swagger UI
    implementation("io.javalin.community.openapi:javalin-redoc-plugin:$openapi") // for ReDoc UI
}

To use kapt, you should also enable Kapt plugin in Gradle:

Maven

Maven setup for Javalin 6.x

<project>
    <properties>
        <javalin.version>6.3.0</javalin.version>
        <javalin.openapi.version>6.3.0</javalin.openapi.version>
    </properties>
    
    <repositories>
        <!-- Snapshots -->
        <repository>
            <id>reposilite-repository</id>
            <url>https://maven.reposilite.com/snapshots</url>
        </repository>
    </repositories>
    
    <dependencies>
        <!-- OpenApi plugin -->
        <dependency>
            <groupId>io.javalin.community.openapi</groupId>
            <artifactId>javalin-openapi-plugin</artifactId>
            <version>${javalin.openapi.version}</version>
        </dependency>
        <!-- Swagger plugin -->
        <dependency>
            <groupId>io.javalin.community.openapi</groupId>
            <artifactId>javalin-swagger-plugin</artifactId>
            <version>${javalin.openapi.version}</version>
        </dependency>
        <!-- ReDoc plugin -->
        <dependency>
            <groupId>io.javalin.community.openapi</groupId>
            <artifactId>javalin-redoc-plugin</artifactId>
            <version>${javalin.openapi.version}</version>
        </dependency>
        <!-- (Optional on 5.3.0+) If you want to use custom ReDoc version, you have to exclude all transitive dependencies -->
        <dependency>
            <groupId>org.webjars.npm</groupId>
            <artifactId>redoc</artifactId>
            <version>2.0.0-rc.70</version>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.10.1</version>
                    <configuration>
                        <annotationProcessorPaths>
                            <annotationProcessorPath>
                                <groupId>io.javalin.community.openapi</groupId>
                                <artifactId>openapi-annotation-processor</artifactId>
                                <version>${javalin.openapi.version}</version>
                            </annotationProcessorPath>
                        </annotationProcessorPaths>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

This plugin is also compatible with Javalin 4.x, see:

Clone this wiki locally