[英]Maven dependency as module
我对Maven并不很精通,我对如何在Maven中处理以下用例感到困惑。
Maven上有一个开源框架。 我希望能够扩展此框架。 在扩展时,我还想测试扩展名是否正确。 因此,我想要一个还包含框架和测试应用程序的项目。
我尝试了一些无效的方法。 我用两个模块创建了一个maven项目samplejsonextend :
模块1。 JsonPath(原始的开源框架)
模块2。 JSONPathTest(这是使用
原始框架)
samplejsonextend pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>samplejsonextend</artifactId>
<groupId>com.samplejsonextend</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.samplejsonextend.JSONPathTest</groupId>
<artifactId>JSONPathTest</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
</project>
Module1 (JSONPath)pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>samplejsonextend</artifactId>
<groupId>com.samplejsonextend</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.2.0</version>
</project>
Module2 (JSONPathTest)pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>samplejsonextend</artifactId>
<groupId>com.samplejsonextend</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.samplejsonextend.JSONPathTest</groupId>
<artifactId>JSONPathTest</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
</project>
上述配置的问题在于,没有为模块1下载任何代码。 那是实现这一目标的正确方法吗? 如果是,那么我能得到一些提示为什么它不起作用吗? 如果这不是正确的方法,那么如何实现呢?
你可以试试这个吗?
samplejsonextend pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<artifactId>samplejsonextend</artifactId>
<groupId>com.samplejsonextend</groupId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>
<modules>
<module>JSONPathTest</module>
<module>JSONPath</module>
</modules>
</project>
Module1(JSONPath)pom.xml:
<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">
<parent>
<artifactId>samplejsonextend</artifactId>
<groupId>com.samplejsonextend</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>samplejsonextend</groupId>
<artifactId>JSONPath</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
Module1(JSONPathTest)pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>samplejsonextend</artifactId>
<groupId>com.samplejsonextend</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.samplejsonextend</groupId>
<artifactId>JSONPathTest</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.samplejsonextend</groupId>
<artifactId>JSONPath</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
与树桩:
samplejsonextend
JSONPath
JSONPathTest
该库的代码将位于类路径上,因此您可以对其进行扩展。
在您的情况下,在父pom中!
<?xml version="1.0" encoding="UTF-8"?>
<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.samplejsonextend</groupId>
<artifactId>samplejsonextend</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>jsonpath</module>
<module>JSONPathTest</module>
</modules>
</project>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.