0

我正在尝试升级我的项目设置以在 Java 11 和 Sling 11 上运行。为此,我一直在尝试将我的 Maven 编译器升级到 3.8.0,但这似乎导致 maven-scr-plugin 出现问题;使其无法扫描仅包含枚举的简单类。

尝试构建 Maven 项目时遇到的错误如下:

    [ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.26.0:scr (generate-scr-scrdescriptor) on project foo-forms.core: {file location} : Unable to scan class files: {package.foo.class} (Class file format probably not supported by ASM ?): IllegalArgumentException -> [Help 1]

这是我的大部分 POM 文件(已删除敏感信息):

 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>aggregate</id>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                        <phase>site</phase>
                    </execution>
                </executions>
            </plugin>
            <!-- Maven Release Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.1</version>
            </plugin>
            <!-- Maven Source Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
                <inherited>true</inherited>
            </plugin>
            <!-- Maven Resources Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <!-- Maven Jar Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.5</version>
            </plugin>
            <!-- Maven Enforcer Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <id>enforce-maven</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <version>[2.2.1,)</version>
                                </requireMavenVersion>
                                <requireJavaVersion>
                                    <message>Project must be compiled with Java 6 or higher</message>
                                    <version>1.10.0</version>
                                </requireJavaVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Maven Compiler Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <release>10</release>
                </configuration>
            </plugin>
            <!-- Maven IntelliJ IDEA Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-idea-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <jdkLevel>1.6</jdkLevel>
                    <linkModules>true</linkModules>
                    <downloadSources>true</downloadSources>
                </configuration>
            </plugin>
            <!-- Maven Eclipse Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                </configuration>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <!-- Maven Clean Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>2.6.1</version>
                </plugin>
                <!-- Maven Resources Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.7</version>
                </plugin>
                <!-- Maven Compiler Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                </plugin>
                <!-- Apache Felix SCR Plugin -->
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-scr-plugin</artifactId>
                    <version>1.26.0</version>
                    <executions>
                        <execution>
                            <id>generate-scr-scrdescriptor</id>
                            <goals>
                                <goal>scr</goal>
                            </goals>
                            <configuration>
                                <!-- Private service properties for all services. -->
                                <properties>
                                    <service.vendor>bar</service.vendor>
                                </properties>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <outputDirectory>${project.build.directory}/classes</outputDirectory>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.slf4j</groupId>
                            <artifactId>slf4j-simple</artifactId>
                            <version>1.7.25</version>
                        </dependency>
                    </dependencies>
                </plugin>
                <!-- Maven Installer Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <!-- Maven Surefire Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.0</version>
                    <configuration>
                        <argLine>
                            --illegal-access=permit
                        </argLine>
                    </configuration>
                </plugin>
                <!-- Maven Failsafe Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.22.0</version>
                    <configuration>
                        <argLine>
                            --illegal-access=permit
                        </argLine>
                    </configuration>
                </plugin>
                <!-- Maven Deploy Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <!-- Apache Sling Plugin -->
                <plugin>
                    <groupId>org.apache.sling</groupId>
                    <artifactId>maven-sling-plugin</artifactId>
                    <version>2.1.0</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>install</goal>
                            </goals>
                            <configuration>
                                <slingUrl>http://${sling.host}:${sling.port}/system/console</slingUrl>
                                <user>-</user>
                                <password>-</password>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <!-- Apache Felix Bundle Plugin -->
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <version>2.5.3</version>
                    <inherited>true</inherited>
                </plugin>
                <!-- Maven Enforcer Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <version>1.4</version>
                </plugin>
                <!-- Maven Dependency Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                </plugin>
                <!-- Build Helper Maven Plugin -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.9.1</version>
                </plugin>
                <!--This plugin's configuration is used to store Eclipse m2e settings 
                    only. It has no influence on the Maven build itself. -->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-enforcer-plugin</artifactId>
                                        <versionRange>[1.0.0,)</versionRange>
                                        <goals>
                                            <goal>enforce</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore/>
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-dependency-plugin</artifactId>
                                        <versionRange>[2.2,)</versionRange>
                                        <goals>
                                            <goal>copy-dependencies</goal>
                                            <goal>unpack</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore/>
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.codehaus.mojo</groupId>
                                        <artifactId>build-helper-maven-plugin</artifactId>
                                        <versionRange>[1.5,)</versionRange>
                                        <goals>
                                            <goal>reserve-network-port</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore/>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <!-- ====================================================================== -->
    <!-- D E P E N D E N C I E S -->
    <!-- ====================================================================== -->
    <dependencyManagement>
        <dependencies>
            <!-- OSGi Dependencies -->
            <dependency>
                <groupId>org.apache.felix</groupId>
                <artifactId>org.apache.felix.scr</artifactId>
                <version>2.1.12</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.felix</groupId>
                <artifactId>org.apache.felix.scr.annotations</artifactId>
                <version>1.12.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>biz.aQute</groupId>
                <artifactId>bndlib</artifactId>
                <version>1.50.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.core</artifactId>
                <version>4.2.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.compendium</artifactId>
                <version>4.2.0</version>
                <scope>provided</scope>
            </dependency>
            <!-- Logging Dependencies -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.5.11</version>
                <scope>provided</scope>
            </dependency>
            <!-- Apache Sling Dependencies -->
            <!-- https://mvnrepository.com/artifact/org.apache.sling/org.apache.sling.api -->
            <dependency>
                <groupId>org.apache.sling</groupId>
                <artifactId>org.apache.sling.api</artifactId>
                <version>2.3.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.sling</groupId>
                <artifactId>org.apache.sling.models.api</artifactId>
                <version>1.0.0</version>
                <scope>provided</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.sling/org.apache.sling.commons.osgi -->
            <dependency>
                <groupId>org.apache.sling</groupId>
                <artifactId>org.apache.sling.commons.osgi</artifactId>
                <version>2.4.0</version>
                <scope>provided</scope>
            </dependency>
            <!-- Servlet API -->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.4</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>jsp-api</artifactId>
                <version>2.1</version>
                <scope>provided</scope>
            </dependency>
            <!-- JCR -->
            <dependency>
                <groupId>javax.jcr</groupId>
                <artifactId>jcr</artifactId>
                <version>2.0</version>
                <scope>provided</scope>
            </dependency>
            <!-- Taglibs -->
            <dependency>
                <groupId>com.day.cq.wcm</groupId>
                <artifactId>cq-wcm-taglib</artifactId>
                <version>5.7.4</version>
                <scope>provided</scope>
            </dependency>
            <!-- Testing -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.8.2</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.5.11</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
                <version>1.9.5</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>junit-addons</groupId>
                <artifactId>junit-addons</artifactId>
                <version>1.4</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.github.tomakehurst</groupId>
                <artifactId>wiremock</artifactId>
                <version>2.14.0</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>4.5.5</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpmime</artifactId>
                <version>4.5.5</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.6</version>
            </dependency>
            <dependency>
                <groupId>com.outreach.workflows</groupId>
                <artifactId>workflow-engine.core</artifactId>
                <version>[1.0.0,)</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.outreach</groupId>
                <artifactId>pojotools.core</artifactId>
                <version>[1.0,)</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.outreach.sql</groupId>
                <artifactId>datasource.core</artifactId>
                <version>[1.0,)</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.outreach</groupId>
                <artifactId>entities.core</artifactId>
                <version>[1.0,)</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.doctusoft</groupId>
                <artifactId>json-schema-java7</artifactId>
                <version>1.4.1.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.5.11</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.8.2</version>
                <scope>provided</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>
  <modules>
    <module>core</module>
    <module>ui</module>
    <module>tests</module>
    <module>launcher</module>
  </modules>

我已经进行了一些故障排除,我的理解是 scr-plugin 根本不支持最新的 maven-compiler,因为一个比另一个早几个月发布(参见下面的链接):

maven-scr-插件

maven 编译器插件

我想知道是否有人遇到过类似的问题并想出了一些解决方法。谢谢!

4

2 回答 2

1

通过迁移到 Java 11,您创建的类文件将被编译为 Java 11 字节码。然后maven-scr-plugin必须扫描此字节码以找到应用于它的注释。除非您能找到maven-scr-plugin支持 Java 11 字节码的版本(我不知道有一个),否则您将需要找到一种替代方法来创建您的声明式服务元数据。

一种选择是开始使用bnd-maven-pluginormaven-bundle-plugin和标准的声明式服务注释,而不是自定义 Felix 注释。请注意,这仍然涉及将这些插件更新到可以支持 Java 11 的版本。我相信bnd-maven-plugin版本 4.1.0 应该与 Java 11 一起正常工作......

于 2018-11-01T10:54:20.697 回答
0

解决方案是迁移到 bnd-maven-plugin,它是 maven-bundle 插件的超集。它拥有更好的开发人员基础,并且也将在未来的 Java 版本中得到维护。

AEM-acs-commons 和最新的 maven 架构类型(本回答时为 23)也已移植到 bnd 插件。

于 2020-07-24T12:43:53.937 回答