0

尝试使用 swagger 2,但我有一个 uri 配置问题。这是我的构建输出和我的 pom.xml 配置。

Maven 中的这个 uri 错误是什么意思?

Maven输出:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.951 s
[INFO] Finished at: 2015-07-15T17:29:38-03:00
[INFO] Final Memory: 14M/226M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.kongchen:swagger-maven-plugin:3.1.0:generate (default) on project xxx: The uri is required. ->
[Help 1]

这是我的 pom.xml 配置

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.rizze.services</groupId>
    <artifactId>xxx</artifactId>
    <packaging>jar</packaging>   
    <version>3.4.2</version>
    <name>wsbase</name>    

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jersey.version>2.17</jersey.version>

    </properties>

    <pluginRepositories>
        <pluginRepository>
            <id>sonatype-snapshot</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>


    <dependencies>


       <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>${jersey.version}</version>
        </dependency>   

       <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>3.0.1</version>
         <scope>provided</scope>
      </dependency>

       <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-core</artifactId>
            <scope>compile</scope>
            <version>1.5.0</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.ws.rs</groupId>
                    <artifactId>jsr311-api</artifactId>
                </exclusion>

          <!-- <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-core</artifactId>
                </exclusion>

                 <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-annotations</artifactId>
                </exclusion> -->      
            </exclusions>
        </dependency>



        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>



        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.5</version>

        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <version>1.7.5</version>

        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>     
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.3</version>
        </dependency>


        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-web</artifactId>
            <version>2.0-rc2</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
    <build>

        <finalName>xxx</finalName>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.0-alpha-2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>set-system-properties</goal>
                        </goals>
                        <configuration>
                            <properties>
                                <property>
                                    <name>log4j.configuration</name>
                                    <value>file:${basedir}/src/main/resources/logs-${env.name}.properties</value>
                                </property>

                            </properties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
             <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
               <source>1.8</source>
               <target>1.8</target>
               <showDeprecation>true</showDeprecation>
               <showWarnings>true</showWarnings>              
               <fork>true</fork>
            </configuration>
         </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <wtpversion>2.0</wtpversion>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <systemProperties>
                        <log4j.debug>true</log4j.debug>
                        <parallel>methods</parallel>
                        <threadCount>10</threadCount>
                    </systemProperties>
                    <includes>
                        <include>**/*.java</include>
                    </includes>
                    <!-- skip>true</skip> -->
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <aggregate>true</aggregate>
                    <argLine>-XX:-UseSplitVerifier</argLine>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                </configuration>
                <executions>
                    <execution>
                        <phase>site</phase>
                        <goals>
                            <goal>cobertura</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


         <plugin>
                <groupId>com.github.kongchen</groupId>
                <artifactId>swagger-maven-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <apiSources>
                      <apiSource>
                            <springmvc>false</springmvc>
                            <locations>com.rizze.services.ressources,</locations>
                            <schemes>http,https</schemes>
                            <host>int.skyos.io</host>
                            <basePath>/api</basePath>
                            <info>
                                <title>${project.artifactId}</title>
                                <version>${project.version}</version> 
                            </info>
                            <templatePath>${basedir}/src/test/resources/swagger/templates/template_rizze</templatePath>
                            <outputPath>${basedir}/target/docs/html/home.jsp</outputPath>
                            <!--  swaggerDirectory>generated/swagger-ui</swaggerDirectory>-->
                        </apiSource>
                    </apiSources>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>






           <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <packagingExcludes>
                        WEB-INF/lib/joda-time-2.5.jar,
                        WEB-INF/lib/log4j-1.2.16.jar,
                        WEB-INF/lib/jcommander-1.30.jar
                        ,WEB-INF/lib/joda-time-2.2.jar
                        ,WEB-INF/lib/guava-11.0.1.jar
                        ,WEB-INF/lib/jsonschema2pojo-0.4.0-javadoc.jar
                        ,WEB-INF/lib/jsonschema2pojo-cli-0.3.7.jar
                        ,WEB-INF/lib/jsonschema2pojo-cli-0.4.0-sources.jar
                        ,WEB-INF/lib/jsonschema2pojo-cli-0.4.0.jar
                        ,WEB-INF/lib/jsonschema2pojo-core-0.3.7.jar
                        ,WEB-INF/lib/jsonschema2pojo-core-0.4.0-sources.jar
                        ,WEB-INF/lib/jsonschema2pojo-core-0.4.0.jar
                        ,WEB-INF/lib/jsonschema2pojo-maven-plugin-0.3.7.jar
                        ,WEB-INF/lib/scala-compiler-2.10.0.jar
                        ,WEB-INF/lib/scala-library-2.10.0.jar
                        ,WEB-INF/lib/scala-reflect-2.10.0.jar
                        ,WEB-INF/lib/scalap-2.10.0.jar

                    </packagingExcludes>

                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
4

1 回答 1

0

找到了答案。Swagger 2 现在已更改域,并且正在使用 io.swagger。我的资源配置错误。为了将 swagger 2 与 maven 一起使用,请执行以下操作:

在 pom.xml 的构建部分中添加

<plugin>
                <groupId>com.github.kongchen</groupId>
                <artifactId>swagger-maven-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <apiSources>
                      <apiSource>
                            <springmvc>false</springmvc>
                            <locations>com.rizze.services.resources;com.rizze.services;com.rizze.sky;</locations>
                            <schemes>http,https</schemes>
                            <host>https://int.skyos.io/sky</host>
                            <basePath>/api</basePath>
                            <info>
                                <title>${project.artifactId}</title>
                                <version>${project.version}</version> 
                            </info>
                            <templatePath>${basedir}/src/test/resources/swagger/templates/template_rizze.hbs</templatePath>
                            <outputPath>${basedir}/target/docs/html/home.jsp</outputPath>
                            <swaggerDirectory>${basedir}/target/docs/swagger-ui</swaggerDirectory>

                        </apiSource>
                    </apiSources>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

并且不要忘记将依赖添加到 pom.xml :

 <dependency>
        <groupId>com.github.kongchen</groupId>
        <artifactId>swagger-maven-plugin</artifactId>
        <version>3.1.0</version>
</dependency>
于 2015-07-16T00:48:16.730 回答