在IntelliJ中使用cofoja注释

时间:2015-07-05 21:17:26

标签: java intellij-idea design-by-contract

我对IntelliJ很新。在尝试使用cofoja代码注释时,我在构建时会收到以下错误。

Error:java: error in contract: package com.google.java.contract.core.agent does not exist
Error:java: error in contract: package com.google.java.contract does not exist

我的项目是针对Oracle JDK 1.7。我使用的是io.konverge发布的cofoja版本和IntelliJ 14.1.4。

<dependency>
  <groupId>io.konverge</groupId>
  <artifactId>cofoja</artifactId>
  <version>2.0.0</version>
</dependency>

从maven命令行构建项目时,我没有收到遇到的错误。

编辑:

这是一个使用maven编译好的cofoja项目示例,但我无法使用IntelliJ构建。

https://github.com/konvergeio/cofoja-example

我已在GitHub上的cofoja项目故障单中附加了此项目的IntelliJ DEBUG构建日志:https://github.com/nhatminhle/cofoja/issues/45

编辑2:

更新了特定于cofoja-example项目的问题。

1 个答案:

答案 0 :(得分:6)

我能够成功配置IntelliJ。希望有人觉得这很有用。

我必须为当前项目配置Annotation Processors。它默认启用,但没有classoutputclasspathsourcepath设置所需的相应配置。我发现了$PROJECT_DIR$宏来创建相应的项目目录的相对路径。 IntelliJ有一个预配置的宏/变量到我的本地maven存储库,所以我用它来引用konvergeio发布的cofoja版本。

我拍了我的配置截图:

intellij-cofoja-annotation-processor

IntelliJ生成的构建日志:

2015-07-12 14:04:11,448 [   1223]  DEBUG - s.incremental.java.JavaBuilder - Compiling chunk [cofoja-example] with options: "-g -deprecation -encoding UTF-8 -source 1.7 -target 1.7 -Acom.google.java.contract.sourcepath=/home/seglo/source/cofoja-example/src/main/java -Acom.google.java.contract.classpath=/home/seglo/.m2/repository/io/konverge/cofoja/2.0.0/cofoja-2.0.0.jar -Acom.google.java.contract.classoutput=/home/seglo/source/cofoja-example/target/classes -s /home/seglo/source/cofoja-example/target/generated-sources/annotations" 

我把Nas的cofoja-example项目的分支推到了我的github。我包含了IntelliJ项目设置。

https://github.com/seglo/cofoja-example

我的项目.idea/compiler.xml

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="CompilerConfiguration">
    <option name="DEFAULT_COMPILER" value="Javac" />
    <resourceExtensions />
    <wildcardResourcePatterns>
      <entry name="!?*.java" />
      <entry name="!?*.form" />
      <entry name="!?*.class" />
      <entry name="!?*.groovy" />
      <entry name="!?*.scala" />
      <entry name="!?*.flex" />
      <entry name="!?*.kt" />
      <entry name="!?*.clj" />
      <entry name="!?*.aj" />
    </wildcardResourcePatterns>
    <annotationProcessing>
      <profile default="true" name="Default" enabled="false">
        <processorPath useClasspath="true" />
      </profile>
      <profile default="false" name="Maven default annotation processors profile" enabled="true">
        <sourceOutputDir name="target/generated-sources/annotations" />
        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
        <outputRelativeToContentRoot value="true" />
        <option name="com.google.java.contract.classoutput" value="$PROJECT_DIR$/target/classes" />
        <option name="com.google.java.contract.classpath" value="$MAVEN_REPOSITORY$/io/konverge/cofoja/2.0.0/cofoja-2.0.0.jar" />
        <option name="com.google.java.contract.sourcepath" value="$PROJECT_DIR$/src/main/java" />
        <processorPath useClasspath="true" />
        <module name="cofoja-example" />
      </profile>
    </annotationProcessing>
    <bytecodeTargetLevel>
      <module name="cofoja-example" target="1.7" />
    </bytecodeTargetLevel>
  </component>
</project>