質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
IntelliJ IDEA

IntelliJ IDEA(インテリジェイ アイディア)は、JetBrains社が開発した、 JavaやScalaなどで利用される統合開発環境です。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Apache Maven

Apache Mavenは、ソフトウェアプロジェクトの管理ツールです。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

1回答

1747閲覧

inteliJで外部ライブラリに正常に追加されているのに、Kluentライブラリが使えない

Rina0x0

総合スコア1

IntelliJ IDEA

IntelliJ IDEA(インテリジェイ アイディア)は、JetBrains社が開発した、 JavaやScalaなどで利用される統合開発環境です。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Apache Maven

Apache Mavenは、ソフトウェアプロジェクトの管理ツールです。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2020/09/23 11:34

inteliJでSpring Bootアプリ(Kotlin)を作成していてKluentライブラリが使えない

KotlinでSpring Bootを使用したWebアプリを作成しようとしています。
テストを書くのにKluentを使用したいと思い、pomファイルにkluentの依存パッケージを追加、
その後Kotlinのテストファイル内でimport文を記載したところ、
External librariesにはきちんと追加されているにもかかわらず、
importが出来ませんでした。

発生している問題はKluentライブラリのImportができないことです

import org.amshove.kluent.shouldThrow

上記のインポート文を書くとamshoveの部分が赤くなり、カーソルを合わせると

Unresolved reference: amshove

と出てしまいます。

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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <packaging>pom</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.knowledge-api</groupId> <artifactId>knowledge-api</artifactId> <version>0.0.1-SNAPSHOT</version> <name>knowledge-api</name> <description>Knowledge-API for Spring Boot</description> <repositories> <repository> <id>central</id> <url>https://repo1.maven.org/maven2/</url> </repository> <repository> <id>jcenter</id> <url>https://jcenter.bintray.com/</url> </repository> </repositories> <properties> <java.version>11</java.version> <kotlin.version>1.3.72</kotlin.version> <junit.jupiter.version>5.5.0</junit.jupiter.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.module</groupId> <artifactId>jackson-module-kotlin</artifactId> </dependency> <dependency> <groupId>io.projectreactor.kotlin</groupId> <artifactId>reactor-kotlin-extensions</artifactId> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-reflect</artifactId> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-stdlib-jdk8</artifactId> </dependency> <dependency> <groupId>org.jetbrains.kotlinx</groupId> <artifactId>kotlinx-coroutines-reactor</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>5.2.2.RELEASE</version> </dependency> <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency> <dependency> <groupId>io.mockk</groupId> <artifactId>mockk</artifactId> <version>1.9.3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.amshove.kluent</groupId> <artifactId>kluent</artifactId> <version>1.61</version> <type>pom</type> <scope>compile</scope> </dependency> </dependencies> <build> <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory> <plugins> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <version>${kotlin.version}</version> <configuration> <args> <arg>-Xjsr305=strict</arg> </args> <compilerPlugins> <plugin>spring</plugin> </compilerPlugins> </configuration> <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-allopen</artifactId> <version>${kotlin.version}</version> </dependency> </dependencies> </plugin> </plugins> </build> </project>

試したこと

File -> Invalid Caches / Restart は試してみました。
あとはMavenのリロード、リビルドプロジェクトなども試しましたが、効果なしでした。
これはなにがまずいのでしょうか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

org.amshove.kluent の依存形式が pom になっているからではないでしょうか。

<dependency> <groupId>org.amshove.kluent</groupId> <artifactId>kluent</artifactId> <version>1.61</version> <type>pom</type> ☆該当箇所 <scope>compile</scope> </dependency>

以下の対応で直りそうです

  • type=pom を削除(クラスへのアクセスが可能になる)
  • テストライブラリであれば、scope を test にする
<dependency> <groupId>org.amshove.kluent</groupId> <artifactId>kluent</artifactId> <version>1.61</version> <scope>test</scope> </dependency>

投稿2020/11/23 11:03

kiino

総合スコア539

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問