まず、ドキュメントの指示に従ってください。
IntelliJ IDEA で注釈処理を構成するには、ダイアログの [設定] > [プロジェクト設定] > [コンパイラ] > [注釈プロセッサ] を使用します。
次に、問題は、sbt が生成されたソース ファイルを に配置していることtarget/scala-2.n/classes/our/package
です。これはコンパイル済み.class
ファイルのディレクトリであるため、ソースを別の場所で生成する必要があります。IDEA 設定を編集してもここでは役に立たないためbuild.sbt
、以下を追加して編集する必要があります。
// tell sbt (and by extension IDEA) that there is source code in target/generated_sources
managedSourceDirectories in Compile += baseDirectory.value / "target" / "generated_sources"
// before compilation happens, create the target/generated_sources directory
compile in Compile <<= (compile in Compile).dependsOn(Def.task({
(baseDirectory.value / "target" / "generated_sources").mkdirs()
}))
// tell the java compiler to output generated source files to target/generated_sources
javacOptions in Compile ++= Seq("-s", "target/generated_sources")
target/
最後に、そのディレクトリの除外を削除して、すべてを無視してはならないことを IDEA に伝える必要があります。ファイル>プロジェクト構造>プロジェクト設定>モジュールに移動し、target
ディレクトリをクリックして「除外」の選択を解除します。または、[プロジェクト] タブでディレクトリを右クリックし、[target
ディレクトリをマーク] > [除外をキャンセル] をクリックします。
この時点で、エディタのサポートが機能していることがわかります。そうでない場合は、実行sbt clean compile
してソースが生成されたことを確認してください。
更新:<<=
最近の sbt バージョンでは構文が削除されています。上記の 2 番目のディレクティブを次のように置き換えることができます。
// before compilation happens, create the target/generated_sources directory
compile in Compile := (compile in Compile).dependsOn(Def.task({
(baseDirectory.value / "target" / "generated_sources").mkdirs()
})).value