1

奇妙な問題に気づきました。Junitを使用してテストケースを実行できますが、Mavenを使用して実行している場合テストケースの1つが失敗しています。Gsonクラスdefが見つからないという不満があります。

Mavenの依存関係でGsonjarを確認できます。

そのため、クラスパスにGsonが含まれていないのではないかと疑っていました。そこで、-Xを使用してMavenを実行し、いくつかの手がかりに気づきました。

[DEBUG] Could not find metadata com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml in local (C:\Users\ra\.m2\repository)
[DEBUG] Skipped remote update check for com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml, locally cached metadata up-to-date.
[DEBUG] Could not find metadata com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml in local (C:\Users\ra\.m2\repository)
[DEBUG] Skipped remote update check for com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml, locally cached metadata up-to-date.
[WARNING] The POM for com.example.libraries:Symbology:jar:1.0.0-SNAPSHOT is invalid, transitive dependencies (if any) will not be available: 2 problems were encountered while building the effective model for com.example.libraries:Symbology:1.0.0-SNAPSHOT
[ERROR] 'dependencies.dependency.artifactId' for ::jar is missing. @ 
[ERROR] 'dependencies.dependency.groupId' for ::jar is missing. @ 

Symbologyプロジェクトに依存するプロジェクトがあり、これはGsonを使用しています。しかし、このログから、推移的な依存関係が含まれていないことがわかります。そのため、Gsonクラスが見つかりません。

これがSymbologypomです。

<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>com.example.libraries</groupId>
<artifactId>Symbology</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Symbology</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>
</dependencies>

これがsymbologyを呼んでいる私のプロジェクトのPomです:

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>com.example.libraries</groupId>
<artifactId>FGF</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<distributionManagement>
    <snapshotRepository>
        <id>example.com</id>
        <name>example.com-snapshots</name>
        <url>http://example/artifactory/libs-snapshots-local</url>
    </snapshotRepository>
</distributionManagement>

<name>FGF</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>
    <dependency>
        <groupId>com.example.libraries</groupId>
        <artifactId>Category</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.example.libraries</groupId>
        <artifactId>Time</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.example.libraries</groupId>
        <artifactId>Display</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
    **<dependency>
        <groupId>com.example.libraries</groupId>
        <artifactId>Symbology</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>**
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.2.0.BUILD-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.directory.studio</groupId>
        <artifactId>org.apache.commons.lang</artifactId>
        <version>2.6</version>
    </dependency>       

</dependencies>

4

1 に答える 1

2

多くの時間を費やした後、最終的に問題を理解しました。

問題は、シンボルアーティファクトをリポジトリにプッシュしているときに、pomをリポジトリにプッシュしていないことです。したがって、シンボルアーティファクトを依存関係として使用している場合、プロジェクトは推移的な依存関係が何であるかを知ることができません。

そこで、pomをjarと一緒にリポジトリにプッシュすると、すべての依存関係を取得できるようになります。

HURRAYYYYYYYYYYYYYYYYY !!!!!!!!!!!!!!!!!!

于 2012-05-29T14:41:20.170 に答える