[英]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.