###問題
NetBeansでMavenのJavaアプリケーションプロジェクトAとBを開発しています。その中で、プロジェクトAはGoogle Guiceに依存していて、プロジェクトBはプロジェクトAに依存しています。依存関係を簡単な図にすると以下のようになっています。
Google Guice <- Project A <- Project B
Mavenの仕様として、Project Bの依存性に、Project Aを追加した時点で、自動的にAの依存性であるGuiceも依存性に追加されるはずなのですが、依存性の欄には表示されませんでした。これが今回の問題です。
Netbeans側では依存性と認識していないため、Project B上でorg.google.inject.InjectなどGuiceのクラスを用いるとエラー表示が出るのですが、コンパイルには成功します。なので恐らく、Mavenは正常に機能しているのですが、Netbeansが正しく依存性を追えていないのかと思われます。
NetBeansにプロジェクトBの依存性として、手動で追加すること無く、Guiceを認識させるにはどのようにすればよいでしょうか?
###依存先(A)
pom.xml
xml
1<?xml version="1.0" encoding="UTF-8"?> 2<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"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>com.example</groupId> 5 <artifactId>dependency</artifactId> 6 <version>0.4.0-beta</version> 7 <packaging>jar</packaging> 8 <properties> 9 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 10 <maven.compiler.source>1.8</maven.compiler.source> 11 <maven.compiler.target>1.8</maven.compiler.target> 12 </properties> 13 14 <build> 15 <finalName>${project.artifactId}-${project.version}</finalName> 16 <resources> 17 <resource> 18 <directory>src/main/resources</directory> 19 <filtering>true</filtering> 20 </resource> 21 </resources> 22 23 <plugins> 24 <plugin> 25 <groupId>org.apache.maven.plugins</groupId> 26 <artifactId>maven-shade-plugin</artifactId> 27 <version>1.5</version> 28 <executions> 29 <execution> 30 <phase>package</phase> 31 <goals> 32 <goal>shade</goal> 33 </goals> 34 <configuration> 35 <finalName>${project.build.finalName}</finalName> 36 <minimizeJar>false</minimizeJar> 37 <shadedArtifactAttached>false</shadedArtifactAttached> 38 </configuration> 39 </execution> 40 </executions> 41 </plugin> 42 </plugins> 43 </build> 44 45 <dependencies> 46 <dependency> 47 <groupId>org.jetbrains</groupId> 48 <artifactId>annotations</artifactId> 49 <version>13.0</version> 50 <scope>compile</scope> 51 </dependency> 52 <dependency> 53 <groupId>com.google.inject</groupId> 54 <artifactId>guice</artifactId> 55 <version>3.0</version> 56 <scope>provided</scope> 57 </dependency> 58 </dependencies> 59</project>
###依存元(B)
pom.xml
xml
1<?xml version="1.0" encoding="UTF-8"?> 2<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"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>com.example</groupId> 5 <artifactId>example</artifactId> 6 <version>0.4.0-beta</version> 7 <packaging>jar</packaging> 8 <properties> 9 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 10 <maven.compiler.source>1.8</maven.compiler.source> 11 <maven.compiler.target>1.8</maven.compiler.target> 12 </properties> 13 14 <build> 15 <finalName>${project.artifactId}-${project.version}</finalName> 16 <resources> 17 <resource> 18 <directory>src/main/resources</directory> 19 <filtering>true</filtering> 20 </resource> 21 </resources> 22 23 <plugins> 24 <plugin> 25 <groupId>org.apache.maven.plugins</groupId> 26 <artifactId>maven-shade-plugin</artifactId> 27 <version>1.5</version> 28 <executions> 29 <execution> 30 <phase>package</phase> 31 <goals> 32 <goal>shade</goal> 33 </goals> 34 <configuration> 35 <finalName>${project.build.finalName}</finalName> 36 <minimizeJar>false</minimizeJar> 37 <shadedArtifactAttached>false</shadedArtifactAttached> 38 </configuration> 39 </execution> 40 </executions> 41 </plugin> 42 </plugins> 43 </build> 44 45 <dependencies> 46 <dependency> 47 <groupId>com.example</groupId> 48 <artifactId>dependency</artifactId> 49 <version>0.4.0-beta</version> 50 <scope>provided</scope> 51 </dependency> 52 </dependencies> 53</project>
Example.java (Mavenによるコンパイルは成功する)
java
1package com.example; 2 3import org.google.inject.Inject; //パッケージorg.google.inject.Injectは存在しません 4 5public class Example { 6 @Inject //org.google.inject.Injectは注釈型ではありません 7 public Example() { 8 } 9}
###補足情報
- java 1.8.0_77; Java HotSpot(TM) 64-Bit Server VM 25.77-b03
- maven 3.3.9
- netbeans 8.1 (Build 201510222201)
- netbeans-maven-plugin 4.30.1
あなたの回答
tips
プレビュー