龙目岛和Maven

时间:2015-02-04 15:36:35

标签: java maven intellij-idea lombok

我试图在IntelliJ上使用Lombok和Maven以及VRaptor,但它不起作用。

我已经在stackoverflow中读了一些信息,但没有解决我的问题,我已经在Intellij中启用了注释处理器,但仍然没有。

我也尝试从命令行编译它(Windows)并且没有工作。

我还尝试创建另一个没有maven的项目并添加库,创建一些用于测试的类,它可以正常工作,编译和运行。

任何帮助?

该项目只有2个类,1个实体和1个控制器

这是我的pom.xml

<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">
<modelVersion>4.0.0</modelVersion>

<groupId>razor</groupId>
<artifactId>controle-de-ponto</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>

<description>Um sistema de controlo de ponto</description>

<repositories>
    <repository>
        <id>projectlombok.org</id>
        <url>http://projectlombok.org/mavenrepo</url>
    </repository>
</repositories>

<properties>
    <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
    <weld.version>2.1.2.Final</weld.version>
</properties>

<dependencies>
    <dependency>
        <groupId>br.com.caelum</groupId>
        <artifactId>vraptor</artifactId>
        <version>4.1.4</version>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>0.11.6</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet-core</artifactId>
        <version>2.1.2.Final</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.jboss.weld</groupId>
        <artifactId>weld-core-impl</artifactId>
        <version>2.1.2.Final</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>el-api</artifactId>
        <version>2.2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-cdi</artifactId>
        <version>5.1.1.Final</version>
    </dependency>

    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
        <!-- uncomment this line on app servers -->
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.velocity</groupId>
        <artifactId>velocity</artifactId>
        <version>1.7</version>
    </dependency>

    <dependency>
        <groupId>org.apache.velocity</groupId>
        <artifactId>velocity-tools</artifactId>
        <version>2.0</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.8.Final</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.34</version>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>br.com.caelum.vraptor</groupId>
        <artifactId>vraptor-jpa</artifactId>
        <version>4.0.2</version>
    </dependency>

    <dependency>
        <groupId>br.com.caelum.vraptor</groupId>
        <artifactId>vraptor-java8</artifactId>
        <version>4.0.0.Final</version>
    </dependency>
</dependencies>

<build>
    <finalName>controle-de-ponto</finalName>
    <!--<outputDirectory>/Users/turini/Documents/workspace/vraptor4/vraptor-blank-project/src/main/webapp/WEB-INF/classes</outputDirectory>-->
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <compilerVersion>1.8</compilerVersion>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

我尝试编译时出错:

[INFO] ------------------------------------------------------------------------
[INFO] Building controle-de-ponto 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ controle-de-ponto ---
[INFO] Using 'ISO-8859-1' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ controle-de-ponto ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\Kennedy\Desktop\controle-de-ponto\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Kennedy/Desktop/controle-de-ponto/src/main/java/br/com/caelum/vraptor/controller/IndexController.java:[37,16] cannot find symbol
  symbol:   method setNome(java.lang.String)
  location: variable usuario of type org.razor.cponto.beans.Usuario
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.167 s
[INFO] Finished at: 2015-02-04T13:41:01-02:00
[INFO] Final Memory: 17M/204M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project controle-de-ponto: Compilation failure
[ERROR] /C:/Users/Kennedy/Desktop/controle-de-ponto/src/main/java/br/com/caelum/vraptor/controller/IndexController.java:[37,16] cannot find symbol
[ERROR] symbol:   method setNome(java.lang.String)
[ERROR] location: variable usuario of type org.razor.cponto.beans.Usuario
[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

5 个答案:

答案 0 :(得分:23)

这可能有效

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>1.16.12</version>
                    </path>                         
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

最新版本:

答案 1 :(得分:6)

这应该按原样运行,与IntelliJ的想法无关。但我会:

  • 确保@Data注释是lombok one
  • 删除存储库定义(maven central很好)
  • 使用最近的lombok版本(1.16.0 撰写本文
  • 重建(mvn clean package

我认为maven在你的情况下找不到lombok jar,或者你可能有另一个@Data

答案 2 :(得分:0)

尝试此依赖

https://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent
http://timmyreilly.azurewebsites.net/flask-socketio-and-more/
https://github.com/miguelgrinberg/Flask-SocketIO/issues/356

答案 3 :(得分:0)

在 projectId 标签中,尝试将 projectlombok.org 替换为 org.projectlombok

答案 4 :(得分:-2)

您需要添加lombok插件:

  <build>
  <plugins>
    <plugin>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok-maven-plugin</artifactId>
      <version>1.16.8.0</version>
      <executions>
        <execution>
          <phase>generate-sources</phase>
          <goals>
            <goal>delombok</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>