我可以看到Maven依赖关系中的Gson jar。
所以我怀疑classpath不包括Gson。所以我用-X运行maven,并注意到一些线索。
[DEBUG]找不到元数据com.example.libraries:符号学:1.0.0-SNAPSHOT / maven-metadata.xml在本地(C:\Users\ra\m2\repository) [DEBUG]跳过远程更新检查com.example.libraries:符号学:1.0.0-SNAPSHOT / maven-metadata.xml,本地缓存的元数据是最新的。 [DEBUG]找不到元数据com.example.libraries:符号学:1.0.0-SNAPSHOT / maven-metadata.xml在本地(C:\Users\ra\m2\repository) [DEBUG]跳过远程更新检查com.example.libraries:符号学:1.0.0-SNAPSHOT / maven-metadata.xml,本地缓存的元数据是最新的。 [警告] com.example.libraries的POM:符号学:jar:1.0.0-SNAPSHOT无效,传递依赖(如果有)不可用:在构建com的有效模型时遇到2个问题.example.libraries:符号学:1.0.0-SNAPSHOT [ERROR]'dependencies.dependency.artifactId'for :: jar缺少。 @ [ERROR]'dependencies.dependency.groupId'for :: jar缺少。 @我有一个依赖于Symbology项目的项目,反过来又使用Gson。 但现在从这个日志我看到传递依赖没有被包含。所以没有找到Gson类。
这里是符号学pom:
< project xmlns = maven.apache/POM/4.0.0xmlns:xsi =www.w3/2001/XMLSchema-instance xsi:schemaLocation =http:/ /maven.apache/POM/4.0.0 maven.apache/xsd/maven-4.0.0.xsd\"> < modelVersion> 4.0.0< / modelVersion> < groupId> com.example.libraries< / groupId> < artifactId>符号学< / artifactId> < version> 1.0.0-SNAPSHOT< / version> < packaging> jar< / packaging> < name>符号学< / name> < url> http://maven.apache< / url> < properties> < project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding> < / properties> <依赖关系> <依赖关系> < groupId> junit< / groupId> < artifactId> junit< / artifactId> < version> 4.10< / version> < scope> test< / scope> < / dependency> <依赖关系> < groupId> com.google.code.gson< / groupId> < artifactId> gson< / artifactId> < version> 2.1< / version> < / dependency> <依赖关系> < groupId> log4j< / groupId> < artifactId> log4j< / artifactId> < version> 1.2.16< / version> < / dependency> < / dependencies>
这是我的Pom正在调用symbology的项目:
xsi:schemaLocation =maven.apache/POM/4.0.0 maven.apache/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< / id> < name> example-snapshots< / name> < url> http:// example / artifactory / libs-snapshots-local< / url> < / snapshotRepository> < / distributionManagement> < name> FGF< / name> < url> http://maven.apache< / url> < properties> < project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding> < / properties> <依赖关系> <依赖关系> < groupId> junit< / groupId> < artifactId> junit< / artifactId> < version> 4.10< / version> < scope> test< / scope> < / dependency> <依赖关系> < groupId> log4j< / groupId> < artifactId> log4j< / artifactId> < version> 1.2.16< / version> < / dependency> <依赖关系> < groupId> com.example.libraries< / groupId> < artifactId>类别< / artifactId> < version> 1.0.0-SNAPSHOT< / version> < / dependency> <依赖关系> < groupId> com.example.libraries< / groupId> < artifactId>时间< / artifactId> < version> 1.0.0-SNAPSHOT< / version> < / dependency> <依赖关系> < groupId> com.example.libraries< / groupId> < artifactId>显示< / artifactId> < version> 1.0.0-SNAPSHOT< / version> < / dependency> **< dependency> < groupId> com.example.libraries< / groupId> < artifactId>符号学< / 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> <依赖关系> < groupId> cglib< / groupId> < artifactId> cglib< / artifactId> < version> 2.2.2< / version> < / dependency> <依赖关系> < groupId> org.apache.directory.studio< / groupId> < artifactId> org.apachemons.lang< / artifactId> < version> 2.6< / version> < / dependency> < / dependencies>解决方案
问题是当我将符号系统工件推送到存储库时,它不会将pom推入存储库。所以当我使用符号系统工件作为依赖项时,我的项目无法知道什么是传递依赖关系。
所以我把我的pom和jar一起推入存储库,现在它能够获得所有的依赖。
I noticed a strange problem. I am able to run my test cases using Junit but when I am running using maven One of the test case is failing. It is complaining that Gson class def is not found.
I am able to see the Gson jar in Maven dependencies.
So I doubted that classpath is not including the Gson. So I ran maven with -X and noticed some clues.
[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. @I have a project which depends on Symbology project and this in turn uses Gson. But now from this log I am seeing transitive dependencies are not getting included. So Gson class is not being found.
Here is the Symbology pom:
<project xmlns="maven.apache/POM/4.0.0" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="maven.apache/POM/4.0.0 maven.apache/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>maven.apache</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>Here is the Pom of my project which is calling symbology :
xsi:schemaLocation="maven.apache/POM/4.0.0 maven.apache/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</id> <name>example-snapshots</name> <url>example/artifactory/libs-snapshots-local</url> </snapshotRepository> </distributionManagement> <name>FGF</name> <url>maven.apache</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.apachemons.lang</artifactId> <version>2.6</version> </dependency> </dependencies> 解决方案Figured Out the Problem Finally after spending lot of time.
The problem is when I am pushing the symbology artifact to repository it is not pushing the pom into repository. So when I am using the symbology artifact as dependency my project is not able to know what are the transitive dependencies.
So I pushed my pom into repository along with jar and now it is able to get all the dependencies.
HURRAYYYYYYYYYYYYYYYYY!!!!!!!!!!!!!!!!!!
发布评论