web-dev-qa-db-ja.com

Maven:パッケージio.swagger.annotationsは存在しません

プロジェクトをswaggerで文書化したい。プロジェクトにswaggerアノテーションとio.springfox依存関係を追加しますが、mvn clean package私は多くのエラーがあります:

PS D:\parent-project> mvn clean package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parent-project                              [pom]
[INFO] module-common-lib                           [jar]
[INFO] module1                                     [jar]
[INFO] module2                                     [jar]
[INFO]
[INFO] ------------< parent-project:parent-project >-------------
[INFO] Building parent-project 0.0.1-SNAPSHOT                      [1/4]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ parent-project ---
[INFO]
[INFO] -------< parent-project:module-common-lib >-------
[INFO] Building module-common-lib 0.0.1-SNAPSHOT           [2/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module-common-lib ---
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ module-common-lib ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\parent-project\module-common-lib\src\main\resources
[INFO] skip non existing resourceDirectory D:\parent-project\module-common-lib\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ module-common-lib ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to D:\parent-project\module-common-lib\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[6,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[7,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[9,2] cannot find symbol
  symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldResponse.Java:[4,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldResponse.Java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseSimple.Java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseSimple.Java:[6,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseSimple.Java:[8,2] cannot find symbol
  symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldResponse.Java:[7,2] cannot find symbol
  symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.Java:[4,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.Java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.Java:[7,2] cannot find symbol
  symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[31,10] cannot find symbol
  symbol:   class ApiModelProperty
  location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[40,10] cannot find symbol
  symbol:   class ApiModelProperty
  location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[49,10] cannot find symbol
  symbol:   class ApiModelProperty
  location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldResponse.Java:[13,10] cannot find symbol
  symbol:   class ApiModelProperty
  location: class com.company.lab.microservices.common.api.HelloWorldResponse
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseSimple.Java:[13,10] cannot find symbol
  symbol:   class ApiModelProperty
  location: class com.company.lab.microservices.common.api.ResponseSimple
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.Java:[14,10] cannot find symbol
  symbol:   class ApiModelProperty
  location: class com.company.lab.microservices.common.api.HelloWorldMessageResponse
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.Java:[23,10] cannot find symbol
  symbol:   class ApiModelProperty
  location: class com.company.lab.microservices.common.api.HelloWorldMessageResponse
[INFO] 19 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent-project 0.0.1-SNAPSHOT ............... SUCCESS [  0.156 s]
[INFO] module-common-lib ................... FAILURE [  1.530 s]
[INFO] module1 ..................... SKIPPED
[INFO] module2 0.0.1-SNAPSHOT ...... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.910 s
[INFO] Finished at: 2018-09-18T09:39:17+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.Apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project module-common-lib: Compilation failure: Compilation failure:
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[6,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[7,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[9,2] cannot find symbol
[ERROR]   symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldResponse.Java:[4,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldResponse.Java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseSimple.Java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseSimple.Java:[6,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseSimple.Java:[8,2] cannot find symbol
[ERROR]   symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldResponse.Java:[7,2] cannot find symbol
[ERROR]   symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.Java:[4,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.Java:[5,30] package io.swagger.annotations does not exist
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.Java:[7,2] cannot find symbol
[ERROR]   symbol: class ApiModel
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[31,10] cannot find symbol
[ERROR]   symbol:   class ApiModelProperty
[ERROR]   location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[40,10] cannot find symbol
[ERROR]   symbol:   class ApiModelProperty
[ERROR]   location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseInfo.Java:[49,10] cannot find symbol
[ERROR]   symbol:   class ApiModelProperty
[ERROR]   location: class com.company.lab.microservices.common.api.ResponseInfo
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldResponse.Java:[13,10] cannot find symbol
[ERROR]   symbol:   class ApiModelProperty
[ERROR]   location: class com.company.lab.microservices.common.api.HelloWorldResponse
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/ResponseSimple.Java:[13,10] cannot find symbol
[ERROR]   symbol:   class ApiModelProperty
[ERROR]   location: class com.company.lab.microservices.common.api.ResponseSimple
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.Java:[14,10] cannot find symbol
[ERROR]   symbol:   class ApiModelProperty
[ERROR]   location: class com.company.lab.microservices.common.api.HelloWorldMessageResponse
[ERROR] /D:/workspace/parent-project/module-common-lib/src/main/Java/com/company/lab/microservices/common/api/HelloWorldMessageResponse.Java:[23,10] cannot find symbol
[ERROR]   symbol:   class ApiModelProperty
[ERROR]   location: class com.company.lab.microservices.common.api.HelloWorldMessageResponse
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.Apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :module-common-lib

このプロジェクトでは、module1とmodule2の両方がcommon-libを使用してJSONを応答タイプとして使用し、swaggerを使用してドキュメントを作成します。

構造プロジェクト:

 parent-project
     pom.xml
     module-common-lib
        pom.xml
        src/main/Java
     module1
        src/main/Java
        src/main/resources
        pom.xml
     module2
        src/main/Java
        src/main/resources
        pom.xml

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/xsd/maven-4.0.0.xsd">


  <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <Java.version>1.8</Java.version> 
    <packageClassifier>exec</packageClassifier> 

    <spring-boot.version>1.5.9.RELEASE</spring-boot.version> 
    <spring-cloud.version>1.4.4.RELEASE</spring-cloud.version>

    <springfox-swagger.version>2.6.1</springfox-swagger.version>
  </properties>

  <dependencyManagement> 
     <dependencies> 

      .....

    <dependency> 
      <groupId>${project.groupId}</groupId> 
      <artifactId>module-common-lib</artifactId> 
      <version>${project.version}</version> 
    </dependency>
    <dependency> 
      <groupId>io.springfox</groupId> 
      <artifactId>springfox-swagger2</artifactId> 
      <version>${springfox-swagger.version}</version> 
    </dependency> 
    <dependency> 
      <groupId>io.springfox</groupId> 
      <artifactId>springfox-swagger-ui</artifactId> 
      <version>${springfox-swagger.version}</version> 
    </dependency>

  </dependencies>

  </dependencyManagement>

  <build> 

    <finalName>${project.artifactId}</finalName> 


     <pluginManagement> 
      <plugins> 
        <plugin> 
          <groupId>org.Apache.maven.plugins</groupId> 
          <artifactId>maven-compiler-plugin</artifactId> 
          <version>3.6.1</version> 
        </plugin> 
        <plugin> 
          <groupId>org.Apache.maven.plugins</groupId> 
          <artifactId>maven-resources-plugin</artifactId> 
          <version>3.0.2</version> 
        </plugin> 
        <plugin> 
          <groupId>org.springframework.boot</groupId> 
          <artifactId>spring-boot-maven-plugin</artifactId> 
          <version>${spring-boot.version}</version> 
        </plugin>
        <plugin>
          <groupId>com.spotify</groupId>
          <artifactId>docker-maven-plugin</artifactId>
          <version>0.4.13</version>
        </plugin> 
      </plugins>
    </pluginManagement> 

    <plugins>
      <plugin> 
          <groupId>org.Apache.maven.plugins</groupId> 
          <artifactId>maven-compiler-plugin</artifactId> 
          <configuration> 
            <source>${Java.version}</source> 
            <target>${Java.version}</target> 
            <encoding>${project.build.sourceEncoding}</encoding> 
          </configuration> 
        </plugin> 
        <plugin>                          
          <groupId>org.Apache.maven.plugins</groupId> 
          <artifactId>maven-resources-plugin</artifactId> 
          <configuration> 
            <encoding>${project.build.sourceEncoding}</encoding> 
          </configuration>  
        </plugin> 
    </plugins>


  </build> 

Pom.xml-module-common-lib

    <properties> 
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencyManagement> 
        <dependencies> 
            <dependency> 
                <groupId>io.springfox</groupId> 
                <artifactId>springfox-swagger2</artifactId> 
            </dependency>
            <dependency> 
                <groupId>io.springfox</groupId> 
                <artifactId>springfox-swagger-ui</artifactId> 
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

Swaggerアノテーションを持つクラスの1つ(他のクラスは同じアノテーションを持っていますが、コードが異なります):

import Java.io.Serializable;
import Java.util.Optional;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel
public class ResponseSimple implements Serializable {
  transient private static final long serialVersionUID = 5106222175899418836L; 
  private ResponseInfo responseInfo = new ResponseInfo(); 

  @ApiModelProperty(notes = "Response info")
  public ResponseInfo getResponseInfo() { 
    return responseInfo; 
  } 

  public void setResponseInfo(ResponseInfo responseInfo) { 
    this.responseInfo = responseInfo; 
  }

  @Override 
  public String toString() { 
    return Optional.of(responseInfo).map(ri -> ri.toString()).orElse(""); 
  }
}

Maven 3.5.4があります

なぜ機能しないのか誰にもわかりますか?

6
Sotnas

module-common-lib/pom.xmlファイルでは、io.springfix:springfox-swagger2要素の<dependencyManagement>依存関係のみを参照します。

子POMでは、<dependencies>要素は<dependencyManagement>要素内にある必要はありません。これは、依存関係を消費するためです(バージョン、スコープ、除外などを管理するだけでなく、親POMが行うことです)。

基本的に、依存関係io.springfox:springfox-swagger2<dependencyManagement>セクションにのみあるという事実は、それが(そして、さらに重要なことに、io.swagger:swagger-annotationspackageを含む推移的な依存関係io.swagger.annotations)でないことを意味しますコンパイルクラスパスに追加されました。

mvn dependency:build-classpathを実行してMavenが構築するクラスパスを表示することでこれを確認できます。

修正は、<dependencyManagement></dependencyManagement>およびmodule-common-lib/pom.xml行を削除することです(ただし[〜#〜] not [〜#〜]parent-project/pom.xmlから、要素がその意図された目的を果たす場合)。

3
David Conneely