Search code examples
javamavenswaggerpayara-micromicroprofile

Swagger on a eclipse microprofile application


I have a java microprofile application that I want to add swagger to. The application has a "custom" Application class

@ApplicationPath("/api")
public class RestApplication extends Application {

    public RestApplication() {
        Swagger swagger = new Swagger();
        new SwaggerContextService().updateSwagger(swagger);

        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setDescription("Parser for sheet music");
        beanConfig.setTitle("Ironfox");
        beanConfig.setVersion("0.0.0");
        beanConfig.setSchemes(new String[]{"http"});
        beanConfig.setBasePath("/api");
        beanConfig.setResourcePackage("se.pro12.ironfox");
        beanConfig.setScan(true);
    }
}

The problem is that it is failing on beanConfig.setScan(true) with the error

java.lang.NoSuchMethodError: com.google.common.collect.Sets$SetView.iterator()Lcom/google/common/collect/UnmodifiableIterator;

And I don't really understand why. I've even tries adding a dependency to google-collections.

Has anyone seen this before or have any ideas of how to solve it?

the pom file that I have

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>se.pro12</groupId>
    <artifactId>ironfox</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <properties>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <runInBackground>false</runInBackground>
    </properties>

    <build>
        <finalName>ironfox</finalName>

        <plugins>
            <plugin>
                <groupId>fish.payara.maven.plugins</groupId>
                <artifactId>payara-micro-maven-plugin</artifactId>
                <version>1.0.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>bundle</goal>
                            <goal>start</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <payaraVersion>4.1.2.173</payaraVersion>
                    <useUberJar>true</useUberJar>
                    <deployWar>false</deployWar>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.eclipse.microprofile</groupId>
            <artifactId>microprofile-bom</artifactId>
            <version>1.1.0</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.18.3</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>LATEST</version>
        </dependency>
        <dependency>
            <groupId>com.google.collections</groupId>
            <artifactId>google-collections</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-jaxrs</artifactId>
            <version>1.5.19</version>
        </dependency>
    </dependencies>
</project>

Solution

  • The version of Payara Micro you're using (4.1.2.173) uses an older version of the Guava library - v19, which doesn't provide the method required by Swagger.

    You have several options:

    • disable classloading delegatation as described in the docs - you can do it locally in glassfish-web.xml in your app
    • copy a newer version of the guava library into the Payara Micro JAR over the existing guava.jar in MICRO-INF/runtime
    • wait a couple of days until Payara Micro 5.182 is released and use MicroProfile Open API instead of Swagger

    Upgrading to a newer version of Payara Micro doesn't help because it still uses the same version of the Guava library.