【问题标题】:What Build Module in IntelliJ actually does for maven moduleIntelliJ 中的 Build Module 对 maven 模块的实际作用
【发布时间】:2018-03-21 04:00:26
【问题描述】:

当我跑步时

mvn clean install

对于我的 Maven 模块,它编译得很好。没有问题。 但是当我在 IntelliJ 中打开我的 pom.xml 文件并选择构建 -> 构建模块时,我会遇到以下问题:

Information:javac 1.8.0_144 was used to compile java sources
Information:Module "mymodule" was fully rebuilt due to project configuration/dependencies changes
Information:09.10.2017 21:16 - Compilation completed with 3 errors and 3 warnings in 23s 991ms
C:\somepath\mymodule\pom.xml
Error:Error:osgi: [mymodule] Exception: java.lang.ClassNotFoundException: org.apache.sling.bnd.models.ModelsScannerPlugin not found, parent:  java.net.URLClassLoader@29453f44 urls:[] exception:java.lang.ClassNotFoundException: org.apache.sling.bnd.models.ModelsScannerPlugin
Error:Error:osgi: [mymodule] Failed to load plugin org.apache.sling.bnd.models.ModelsScannerPlugin;generatePackagesHeader=true, error: java.lang.ClassNotFoundException: org.apache.sling.bnd.models.ModelsScannerPlugin not found, parent:  java.net.URLClassLoader@29453f44 urls:[] exception:java.lang.ClassNotFoundException: org.apache.sling.bnd.models.ModelsScannerPlugin 
Error:Error:osgi: [mymodule] Cannot load the plugin org.apache.sling.bnd.models.ModelsScannerPlugin

这是一个带有 AEM 代码的模块,它使用 maven-sling-plugin。它适用于项目中的其他开发人员。因为它在直接从 maven 执行时有效,所以我试图了解 IntelliJ 在后台执行的操作。但实际上,我的问题是那些编译问题。

根据我的发现,IntelliJ 在构建完成后不会调用 maven。有什么想法可以找到从 IntelliJ 运行和直接从 Maven 运行之间的差异吗?

【问题讨论】:

  • 类路径可能有所不同。是否可以通过示例项目重现该问题?
  • 你们有没有从最初的项目设置中修改任何东西?

标签: maven intellij-idea aem maven-plugin sling-models


【解决方案1】:

能否请您检查一下您的核心 pom 文件。它应该包含这样的插件部分:

<plugin> <!-- Enable registration of Sling Models classes via bnd plugin --> org.apache.sling.bnd.models.ModelsScannerPlugin, <!-- Allow the processing of SCR annotations via a bnd plugin --> org.apache.felix.scrplugin.bnd.SCRDescriptorBndPlugin;destdir=${project.build.outputDirectory} </plugin>

但如果您使用 aem 原型创建项目,则标签看起来像'<_plugin>

【讨论】:

    【解决方案2】:

    这里发生的情况是无法使用当前的 ClassLoader 找到 ModelScanner 插件。造成这种情况的原因可能是您使用的是 IntelliJ IDEA Ultimate,它带有一个已预安装的 OSGI 插件,名为“Osmorc”。如果此 OSGI 插件处于活动状态,它将确定用于构建 OSGI 相关项目的类加载器。

    因此,只需在 IntelliJ 中停用此 Osmorc 插件即可让您的构建从项目 POM.xml 文件中的 maven-bundle-plugin 配置中提到的 ModelScannerPlugin 恢复到类加载器,这应该可以解决问题。

    如果这仍然导致类似的 Maven 构建错误,请确保在 POM.xml 文件中将 Maven 依赖项“org.apache.sling.bnd.model”添加到 maven-bundle-plugin。

    <!-- Apache Felix Bundle Plugin -->
    <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>3.3.0</version>
        <inherited>true</inherited>
        <extensions>true</extensions>
        <executions>
            <!-- Configure extra execution of 'manifest' in process-classes phase to make sure SCR metadata is generated before unit test runs -->
            <execution>
                <id>scr-metadata</id>
                <goals>
                    <goal>manifest</goal>
                </goals>
                <configuration>
                    <supportIncrementalBuild>true</supportIncrementalBuild>
                </configuration>
            </execution>
        </executions>
        <configuration>
            <exportScr>true</exportScr>
            <instructions>
                <!-- Enable processing of OSGI DS component annotations -->
                <_dsannotations>*</_dsannotations>
                <!-- Enable processing of OSGI metatype annotations -->
                <_metatypeannotations>*</_metatypeannotations>
                <_plugin>org.apache.sling.bnd.models.ModelsScannerPlugin;generatePackagesHeader=true</_plugin>
            </instructions>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>org.apache.sling</groupId>
                <artifactId>org.apache.sling.bnd.models</artifactId>
                <version>1.0.0</version>
            </dependency>
        </dependencies>
    </plugin>
    

    【讨论】:

    • 干杯!这让我有些难过。就我而言,它不是 Osmorc 插件,而是我安装了另外两个 OSGi 插件。禁用它们允许我直接从 IDE 触发测试。
    猜你喜欢
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多