CCC
CCC

Reputation: 200

Setting maven to have a framework and other projects that use it

I created a Maven project that i should use as a framework. This framework has some dependencies:

<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>

I'd like to create other Maven projects, separated from the framework project, that will have their own pom.xml with the framework dependency. If possible, they should inherit dependencies from the framework project.

<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>

Unfortunately I don't know where to start with the maven settings. I'm not even sure if the pom files are correct. I only know that i can't simply put the jar dependency into the test project and run it. Can you help me out?

Thank you

Upvotes: 0

Views: 89

Answers (3)

CCC
CCC

Reputation: 200

Problem was that my classes where in the wrong folders. They were in src/test/java while they had to be in src/main/java. Also in the test project pom i removed scope and systemPath as suggested by Andrew Fomin

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

I had an error

Missing artifact SeleniumJavaFramework:SeleniumJavaFramework:jar:0.1.1-SNAPSHOT

because, as you can see, version was wrong.

Thank you all

Upvotes: 0

user12637910
user12637910

Reputation:

I suggest to follow the maven official guide for learning how inheritance works in maven and adapt this to your logic:

http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance

Upvotes: 0

Andrew Fomin
Andrew Fomin

Reputation: 344

If you are working at single project, you can create a parent pom that include your TestOne app and Framework as two modules, so you'll have 3 poms (search for maven multimodule project). If your framework is a library for different projects, you need a repository (ie nexus), where your Framework can be deployed to. Then you can use it as a dependency in other projects (dependencies of Framework will be included automatically)

Upvotes: 1

Related Questions