# Build Tools

## Maven

### Dependency file

{% code title="pom.xml" %}
```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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-maven</artifactId>
    <packaging>jar</packaging>
    <version>0.1.0</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>hello.HelloWorld</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
```
{% endcode %}

* `<modelVersion>`. POM model version (always 4.0.0).
* `<groupId>`. Group or organization that the project belongs to. Often expressed as an inverted domain name.
* `<artifactId>`. Name to be given to the project’s library artifact (for example, the name of its JAR or WAR file).
* `<version>`. Version of the project that is being built.
* `<packaging>` - How the project should be packaged. Defaults to "jar" for JAR file packaging. Use "war" for WAR file packaging.

### Command

```bash
mvn compile
```

* &#x20;compiled _.class_ files which is bytecode file in the _target/classes_ directory.

```
mvn package
```

* packaging the code up in a JAR file within the _target_ directory. The name of the JAR file will be based on the project’s `<artifactId>` and `<version>`. For example, given the minimal _pom.xml_ file from before, the JAR file will be named _gs-maven-0.1.0.jar_.
* After that the artifact can be executed by

```bash
java -jar target/gs-maven-0.1.0.jar
```

## Gradle

### Dependency file

{% code title="build.gradle" %}
```gradle
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'

mainClassName = 'hello.HelloWorld'

// tag::repositories[]
repositories { 
    mavenCentral() 
}
// end::repositories[]

// tag::jar[]
jar {
    archiveBaseName = 'gs-gradle'
    archiveVersion =  '0.1.0'
}
// end::jar[]

// tag::dependencies[]
sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    implementation "joda-time:joda-time:2.2"
    testImplementation "junit:junit:4.12"
}
// end::dependencies[]

// tag::wrapper[]
// end::wrapper[]
```
{% endcode %}

### Command

```
gradle build
```

To see the results of the build effort, take a look in the _build_ folder. Therein you’ll find several directories, including these three notable folders:

* _classes_. The project’s compiled .class files.
* _reports_. Reports produced by the build (such as test reports).
* _libs_. Assembled project libraries (usually JAR and/or WAR files).
