exp 3

 #delete MyMavenApp in folder

mvn archetype:generate -DgroupId=com.example -DartifactId=MyMavenApp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

cd MyMavenApp

sudo snap install tree

tree

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


  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>

  <artifactId>MyMavenApp</artifactId>

  <version>1.0-SNAPSHOT</version>

  <packaging>jar</packaging>


  <properties>

    <!-- Java version -->

    <maven.compiler.source>17</maven.compiler.source>

    <maven.compiler.target>17</maven.compiler.target>


    <!-- JUnit and Surefire versions -->

    <junit.jupiter.version>5.10.1</junit.jupiter.version>

    <surefire.plugin.version>3.0.0-M7</surefire.plugin.version>

  </properties>


  <dependencies>

    <!-- JUnit 5 API for writing tests -->

    <dependency>

      <groupId>org.junit.jupiter</groupId>

      <artifactId>junit-jupiter-api</artifactId>

      <version>${junit.jupiter.version}</version>

      <scope>test</scope>

    </dependency>


    <!-- JUnit 5 Engine for running tests -->

    <dependency>

      <groupId>org.junit.jupiter</groupId>

      <artifactId>junit-jupiter-engine</artifactId>

      <version>${junit.jupiter.version}</version>

      <scope>test</scope>

    </dependency>

  </dependencies>


  <build>

    <plugins>

      <!-- Compiler plugin for Java 17 -->

      <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-compiler-plugin</artifactId>

        <version>3.8.1</version>

        <configuration>

          <source>${maven.compiler.source}</source>

          <target>${maven.compiler.target}</target>

        </configuration>

      </plugin>


      <!-- Surefire plugin to run JUnit 5 tests -->

      <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-surefire-plugin</artifactId>

        <version>${surefire.plugin.version}</version>

        <configuration>

          <argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>

        </configuration>

      </plugin>

    </plugins>

  </build>


</project>

-----------------------------------------------------------------------------------------------------------

gedit src/main/java/com/example/App.java

------------------------------------------------------------------------------------------------------------

package com.example;


public class App {

    public String getMessage() {

        return "Hello World!";

    }


    public static void main(String[] args) {

        System.out.println(new App().getMessage());

    }

}

------------------------------------------------------------------------------------------------------------

gedit src/test/java/com/example/AppTest.java

------------------------------------------------------------------------------------------------------------

package com.example;


import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;


class AppTest {


    @Test

    void testGetMessage() {

        App app = new App();

        assertEquals("Hello World!", app.getMessage(), "Message should be 'Hello World!'");

    }

}

------------------------------------------------------------------------------------------------------------

mvn clean install

java -cp target/classes com.example.App


gradle init

tree

gedit build.gradle

------------------------------------------------------------------------

plugins {

     id 'application'

    id 'java-library' 

    id 'maven-publish' 

}

repositories {

    mavenLocal()

    maven {

        url = uri('https://repo.maven.apache.org/maven2/')

    }

}

dependencies {

    testImplementation libs.junit.junit

}

group = 'com.example'

version = '1.0-SNAPSHOT'

description = 'HelloMaven'

java.sourceCompatibility = JavaVersion.VERSION_1_8 

application {

    mainClass = 'com.example.App'

}

publishing {

    publications {

        maven(MavenPublication) {

            from(components.java)

        }

    }

}

---------------------------------------------------------------------------------------------

gradle build

gradle run



Comments

Popular posts from this blog

pom.xml

exp 6

exp 5