Build Tools
Maven
Dependency file
<?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>
<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
mvn compile
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
java -jar target/gs-maven-0.1.0.jar
Gradle
Dependency file
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[]
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).
Last updated
Was this helpful?