19

私は、aspectjコンパイラでプロジェクトをコンパイルするためにaspectj mavenプラグインを使用しようとし、次にクラスを「war」ファイルにパッケージ化しようとしました。残念ながら、次の構成 (pom.xml) では機能しません。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.liferay.maven.plugins</groupId>
            <artifactId>liferay-maven-plugin</artifactId>
            <version>${liferay.maven.plugin.version}</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                </execution>
            </executions>
            <configuration>
                <autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
                <appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
                <appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
                <appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
                <liferayVersion>${liferay.version}</liferayVersion>
                <pluginType>portlet</pluginType>

            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <source>1.7</source>
                <target>1.7</target>
                <showWarnings>true</showWarnings>
                <failOnError>true</failOnError>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.7</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilationLevel>1.7</compilationLevel>
                <encoding>UTF-8</encoding>
            </configuration>
            <executions>
                <execution>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.7.4</version>
    <type>jar</type>
</dependency>

mvn clean install次の例外が表示された後:

[INFO] --- aspectj-maven-plugin:1.7:compile (default) @ tvbs-portlet ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[ERROR] Missing message: configure.incompatibleComplianceForSource in: org.aspectj.ajdt.ajc.messages
    <unknown source file>:<no line information>

[ERROR] no sources specified
    <unknown source file>:<no line information>

[ERROR] AspectJ Compiler 1.8.2

    Usage: <options> <source file | @argfile>..

AspectJ-specific options:
    -inpath <list>      use classes in dirs and jars/zips in <list> as source

誰かが私にいくつかの解決策を提案できますか?

4

5 に答える 5

16

既知の問題のようですhttp://jira.codehaus.org/browse/MASPECTJ-125

pom ファイルに以下を追加することで修正できます。

<complianceLevel>1.6</complianceLevel>
于 2014-11-11T11:08:58.553 に答える
9

更新:この回答で AspectJ Maven 構成について述べたことはすべて正しいですが、手元にある具体的な問題の根本原因 - 悪い Maven 依存関係管理 - は私の他の回答で説明されています。それが受け入れられた答えであり、これではない方が良いでしょう。


  • ユーザー codelion のヒントは理にかなっています。<compilationLevel>タグを (タイプミス?) に変更してください<complianceLevel>
  • プラグイン バージョン 1.6 にダウングレードする必要はありません。1.7 のままでかまいません。
  • セクション内で構成を再度指定する必要もありません<execution>。プラグイン レベルの構成で十分です。
  • プラグイン 1.7 のデフォルトの AspectJ バージョンは 1.8.2 であるため、おそらく 1.7.4 へのランタイム依存関係が機能することに注意してください。難しい要件ではありませんが、理にかなっていると思います。
  • プラグインとランタイムを現在のバージョンの AspectJ 1.8.4 にアップグレードしたい場合もあります。これは、プラグイン構成に目的のspectjtoolsバージョンへの依存関係を追加することによっても実現できます。
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.source-target.version>1.8</java.source-target.version>
        <aspectj.version>1.8.4</aspectj.version>
    </properties>

    <build>
        <pluginManagement>
             <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>aspectj-maven-plugin</artifactId>
                    <version>1.7</version>
                    <configuration>
                        <showWeaveInfo>true</showWeaveInfo>
                        <source>${java.source-target.version}</source>
                        <target>${java.source-target.version}</target>
                        <Xlint>ignore</Xlint>
                        <complianceLevel>${java.source-target.version}</complianceLevel>
                        <encoding>UTF-8</encoding>
                        <verbose>true</verbose>
                    </configuration>
                    <executions>
                        <execution>
                            <!-- IMPORTANT -->
                            <phase>process-sources</phase>
                            <goals>
                                <goal>compile</goal>
                                <goal>test-compile</goal>
                            </goals>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjtools</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjrt</artifactId>
                <version>${aspectj.version}</version>
                <scope>runtime</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
        </dependency>
    </dependencies>
于 2014-11-11T14:08:39.563 に答える
5

Maven プロジェクトhttps://github.com/dmitrievanthony/test-aspectjを調べたところ、

  • この問題は AspectJ Maven Plugin とはまったく関係ありません。
  • 同じコンパイル エラーが Maven Compiler Plugin でも発生し、
  • あなたの問題の根本的な原因は、単に依存関係の管理が悪いことです。

IntelliJ IDEA の「find class」のスクリーンショット (フルサイズはこちら) は次のとおりです。

クラス LockModeType は、プロジェクトで 3 回見つかりました

ご覧のとおり、クラスLockModeTypeは 3 つ (3 つ!) の依存関係で見つかります。そのうちの 1 つには、期待される列挙値を含まないバージョンのクラスが含まれています。この依存関係を削除すると、コードはコンパイルされます。

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>ejb3-persistence</artifactId>
        <version>1.0.2.GA</version>
    </dependency>

たぶん、依存関係をクリーンアップする必要があります。Maven Dependency Plugin は、そのような目的で使用できdependency:analyzeますdependency:tree

于 2014-11-12T12:38:18.333 に答える
1

プラグイン構成を次のように変更すると機能します。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.6</version>
    <configuration>
        <complianceLevel>1.7</complianceLevel>
        <source>1.7</source>
        <target>1.7</target>
        <encoding>UTF-8</encoding>
    </configuration>
    <executions>
        <execution>
            <phase>process-sources</phase>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <complianceLevel>1.7</complianceLevel>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </execution>
    </executions>
</plugin>

しかし、この後、さまざまなコンパイル エラーが発生します。

[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.6:compile (default) on project tvbs-portlet: Compiler errors:
[ERROR] error at Entitle.class, entitleId, LockModeType.PESSIMISTIC_WRITE);
[ERROR]
[ERROR] /Users/<...>/ejb/BillingEJB.java:43:0::0 PESSIMISTIC_WRITE cannot be resolved or is not a field
[ERROR] error at .createQuery("select e from Entitle e " +
[ERROR]
[ERROR] /Users/<...>/ejb/EntitleEJB.java:62:0::0 The method createQuery(String) in the type EntityManager is not applicable for the arguments (String, Class<Entitle>)
[ERROR] error at return entityManager.createQuery(
[ERROR] ^^

原因は、aspectj プラグインのパラメーターが正しくない可能性がありますか?

于 2014-11-11T12:19:16.773 に答える
0

モジュールに *.java などのソース コードがあることを確認してください。バージョン 4.0.6 で CAS をコンパイルすると、このエラーが発生します。cas-server-uber-webapp の src フォルダーにソース コードがないことがわかりました。親 pom.xml からモジュールを削除するだけです。

于 2016-12-23T02:50:52.023 に答える