设置maven有一个框架和其他使用它的项目。

问题描述 投票:0回答:2

我创建了一个Maven项目,我应该把它作为一个框架。这个框架有一些依赖性。

<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>SeleniumJavaFramework</groupId>
    <artifactId>SeleniumJavaFramework</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>7</maven.compiler.source>
        <maven.compiler.target>7</maven.compiler.target>
    </properties>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0-alpha-6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.1.0</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13</version>
            <scope>compile</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>4.1.6</version>
            <scope>compile</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.2</version>
        </dependency>
    </dependencies>
</project>

我想创建其他的Maven项目,从框架项目中分离出来,有自己的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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>RicercaGoogle</groupId>
    <artifactId>RicercaGoogle</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>TestOne</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>7</maven.compiler.source>
        <maven.compiler.target>7</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>SeleniumJavaFramework</groupId>
            <artifactId>SeleniumJavaFramework</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>patofmyjar.jar</systemPath>
        </dependency>
    </dependencies>
</project>

不幸的是,我不知道从哪里开始进行maven设置。我甚至不确定pom文件是否正确。我只知道我不能简单地把jar依赖放到测试项目中运行。你能帮帮我吗?

谢谢你的帮助。

java maven testing dependencies testng
2个回答
1
投票

如果你是在单个项目中工作,你可以创建一个父POM,将TestOne应用和Framework作为两个模块,这样你就有3个POM(搜索maven多模块项目)。如果你的框架是一个不同项目的库,你需要一个仓库(即nexus),你的Framework可以部署到那里。然后你就可以在其他项目中使用它作为依赖关系(Framework的依赖关系会被自动包含在内)。


0
投票

我建议按照maven官方指南来学习maven中的继承工作,并将其应用到你的逻辑中。

http:/maven.apache.orgguidesintroductionintroduction-to-the-pom.html#Project_Inheritance。


0
投票

问题是我的课在错误的文件夹里,他们在 src/test/java 而他们必须在 src/main/java在测试项目中,我还按照Andrew Fomin的建议删除了scope和systemPath。

<dependency>
            <groupId>SeleniumJavaFramework</groupId>
            <artifactId>SeleniumJavaFramework</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

我有一个错误

Missing artifact SeleniumJavaFramework:SeleniumJavaFramework:jar:0.1.1-SNAPSHOT

因为,你可以看到,版本是错误的。

谢谢大家

© www.soinside.com 2019 - 2024. All rights reserved.