myt*_*123 1 java module intellij-idea maven lombok
我正在尝试使用 maven 和 hibernate 创建一个模块化 javafx 应用程序。昨天,我的 module-info.java 文件中出现了很多错误,因此我决定从头开始重新创建项目以隔离问题。
\n\n该项目将无法编译,因为 IDE 无法找到 lombok 生成的方法。当我检查 .class 文件时,它没有任何自动生成的样板。当我没有 module-info.java 文件时,我不会遇到此问题。
\n\n根据我在其他有关 lombok 的帖子中看到的一些建议,我确保在 IntelliJ 中启用了注释处理并启用了 lombok 插件。\n当我将 lombok.jar 添加到项目结构中的依赖项时,module-info.jar 无法编译,并且当我将光标放在“需要 lombok”上时,intelliJ 显示“不明确的模块引用:lombok”。\n模块声明也用红色下划线显示,显示以下消息:“模块\'AlienDB\'从\'lombok\'和\'lombok\'读取包\'lombok\'。
\n\n这是我的 pom.xml 文件:
\n\n<?xml version="1.0" encoding="UTF-8"?>\n\n<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\n <modelVersion>4.0.0</modelVersion>\n\n <groupId>Aliens</groupId>\n <artifactId>AlienDB</artifactId>\n <version>1.0-SNAPSHOT</version>\n\n <name>AlienDB</name>\n <!-- FIXME change it to the project\'s website -->\n <url>http://www.example.com</url>\n\n <properties>\n <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n <maven.compiler.source>9</maven.compiler.source>\n <maven.compiler.target>9</maven.compiler.target>\n </properties>\n\n <dependencies>\n\n\n <dependency>\n <groupId>org.projectlombok</groupId>\n <artifactId>lombok</artifactId>\n <version>1.18.8</version>\n <scope>provided</scope>\n </dependency>\n\n <dependency>\n <groupId>org.hibernate</groupId>\n <artifactId>hibernate-core</artifactId>\n <version>5.4.3.Final</version>\n </dependency>\n\n <dependency>\n <groupId>mysql</groupId>\n <artifactId>mysql-connector-java</artifactId>\n <version>8.0.16</version>\n </dependency>\n\n\n\n </dependencies>\n\n <build>\n <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->\n <plugins>\n <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->\n <plugin>\n <artifactId>maven-clean-plugin</artifactId>\n <version>3.1.0</version>\n </plugin>\n <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->\n <plugin>\n <artifactId>maven-resources-plugin</artifactId>\n <version>3.0.2</version>\n </plugin>\n <plugin>\n <artifactId>maven-compiler-plugin</artifactId>\n <version>3.8.0</version>\n </plugin>\n <plugin>\n <artifactId>maven-surefire-plugin</artifactId>\n <version>3.0.0-M1</version>\n </plugin>\n <plugin>\n <artifactId>maven-jar-plugin</artifactId>\n <version>3.0.2</version>\n </plugin>\n <plugin>\n <artifactId>maven-install-plugin</artifactId>\n <version>2.5.2</version>\n </plugin>\n <plugin>\n <artifactId>maven-deploy-plugin</artifactId>\n <version>2.8.2</version>\n </plugin>\n <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->\n <plugin>\n <artifactId>maven-site-plugin</artifactId>\n <version>3.7.1</version>\n </plugin>\n <plugin>\n <artifactId>maven-project-info-reports-plugin</artifactId>\n <version>3.0.0</version>\n </plugin>\n </plugins>\n </pluginManagement>\n </build>\n</project>\nRun Code Online (Sandbox Code Playgroud)\n\n模块信息.java 文件:
\n\n\nmodule AlienDB {\n\n requires lombok;\n requires java.persistence;\n requires org.hibernate.orm.core;\n requires java.naming;\n\n exports Aliens;\n}\n\nRun Code Online (Sandbox Code Playgroud)\n\n外星人1.java
\n\npackage Aliens;\n\nimport lombok.Data;\nimport javax.persistence.Column;\nimport javax.persistence.Entity;\nimport javax.persistence.Id;\n\n@Data\n@Entity (name = "alien2")\npublic class Alien1 {\n\n @Id\n @Column(name = "aID", nullable = false)\n private int aID;\n\n @Column(name = "aName")\n private String aName;\n\n\n}\nRun Code Online (Sandbox Code Playgroud)\n\n主要应用程序:
\n\npackage Aliens;\n\nimport org.hibernate.Session;\nimport org.hibernate.SessionFactory;\nimport org.hibernate.Transaction;\nimport org.hibernate.boot.registry.StandardServiceRegistryBuilder;\nimport org.hibernate.cfg.Configuration;\nimport org.hibernate.service.ServiceRegistry;\n\n\npublic class App \n{\n public static void main( String[] args )\n\n {\n Configuration con = new Configuration().configure().addAnnotatedClass(Alien1.class);\n ServiceRegistry reg = new StandardServiceRegistryBuilder().applySettings(con.getProperties()).build();\n SessionFactory sf = con.buildSessionFactory(reg);\n\n Session session = sf.openSession();\n Transaction tx = session.beginTransaction();\n\n Alien1 alienName = session.get(Alien1.class, 1);\n //System.out.println(alienName.getAName());\n\n tx.commit();\n\n session.close();\n sf.close();\n }\n}\n\nRun Code Online (Sandbox Code Playgroud)\n\n当我运行如上所示的应用程序并将 lombok jar 添加到依赖项时,出现以下错误:
\n\n引导层初始化期间发生错误\njava.lang.module.ResolutionException:模块 lombok 未读取导出 org.mapstruct.ap.spi 的模块
\n\n当我从项目结构中的依赖项中删除 lombok.jar 时,module-info.jar 不会显示任何错误,但出现以下错误:
\n\n引导层初始化期间发生错误\njava.lang.module.FindException: 未找到 AlienDB 所需的模块 lombok
\n\n无论哪种情况,当我取消注释打印行语句时,我都会得到以下方法,大概是因为 lombok 无法生成样板:
\n\n错误:(24, 37) java: 找不到符号\n 符号: 方法 getAName()\n 位置: Aliens.Alien1 类型的变量 AlienName
\n\n模块结构:
\n\nC:.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80.idea\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80src\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80main\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80java\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80Aliens\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80resources\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80test\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80java\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80Aliens\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80target\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80classes\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80generated-sources\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80annotations\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80generated-test-sources\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80test-annotations\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80maven-archiver\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80maven-status\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80maven-compiler-plugin\n \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80compile\n \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80default-compile\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80testCompile\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80default-testCompile\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80surefire-reports\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80test-classes\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80Aliens\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80META-INF\nRun Code Online (Sandbox Code Playgroud)\n\n我正在使用 intelliJ Ultimate 2019.1 \nSDK 是 java 11 \n语言级别设置为 9。
\n\n编辑:我也尝试在 Eclipse 上运行它,但遇到了同样的问题 - Lombok 方法没有生成,即使它们在建议框中显示为有效建议。
\n我设法通过添加以下 pom.xml 文件来解决此问题。
<configuration>
<source>9</source>
<target>9</target>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1754 次 |
| 最近记录: |