Skip to content

Instantly share code, notes, and snippets.

@mcgivrer
Last active March 20, 2024 07:45
Show Gist options
  • Save mcgivrer/4c6905f869c39eaea083afe44fa57a1c to your computer and use it in GitHub Desktop.
Save mcgivrer/4c6905f869c39eaea083afe44fa57a1c to your computer and use it in GitHub Desktop.
The -Ultimate Maven Project Kit- to build project with sources, javadoc, only-one-shaded-jar, windows executable, publish artifact to git, verify version and add licenses !
/target/
/.classpath
/.project
/.vscode
/.idea
/dependency-reduced-pom.xml
/bin/
#
# [[organization_name]] [[project_year]]
# [[project_name]]
#
language: java
jdk:
- oraclejdk8
#before_install:
# - Commands to execute before install

[[project_name]]

TravisCI Dependency Status

[[organization_name]] / [[project_name]] / [[project_year]]

This project is part of the [[project_name]] course from GameDev Basics Java provided by the [[organization_name]] site.

Goal

TODO

Compile

To compile the full project, please execute the following command :

    $> mvn clean install

Execute the game

  • On any platform (Linux, MacOS, Windows)

to execute the compiled jar, please execute the command bellow :

    $> mvn exec:java

or :

    $> java -jar [[project_name]]-[[project_version]]-jar-with-dependencies.jar
  • Specifically to Windows platform

To build a windows executable file, you must run :

    C:\> mvn clean install site

This will build a [[project_name]].exe into the target directory.

Then you can directly execute :

    C:\> target/[[project_name]].exe

If needed, you can also add some arguments from the bellow table:

argument short sample default Description
--debug -d -d [0-4] 0 Request debug information with the level

Executing the following line bello:

    C:/> target/[[project_name]].exe -d 1

will open the next window :

The welcome title The options

Edit

Import this project as an Existing Maven Project into your prefered IDE, (like Eclipse ?)

Some screen shots ?

States

TODO

Maven Repo ?

To publish to the right maven repo, just execute the following lines:

    $> mvn clean site deploy

Before execution, be sure that your settings.xml contains a server entry with your login/password for the github repository.

<servers>
	<server>
		<id>github</id>
		<username>[GITHUB-USERNAME]</username>
		<password>[GITHUB-USERPASSWORD]</password>
	</server>
</servers>

Have Fun !

Send a mail to [[organization_name]]

#
# [[organization_name]] [[project_year]]
# [[project_name]]
#
image: maven:3.3.9
pipelines:
default:
- step:
caches:
- maven
script: # Modify the commands below to build your repository.
- mvn -B verify # -B batch mode makes Maven less verbose
<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>[[project_groupid]]</groupId>
<artifactId>[[project_artifactid]]</artifactId>
<version>[[project_version]]</version>
<name>[[project_name]]</name>
<description>The basics for the Game development on the java platform.</description>
<url>https://[[repo_git_hostname]]/[[repo_git_username]]/${project.name}</url>
<inceptionYear>[[project_year]]</inceptionYear>
<!-- Authors and Designers -->
<contributors>
<contributor>
<name>[[author_name]]</name>
<email>[[author_email]]</email>
<organization>[[author_organization]]</organization>
<organizationUrl>[[author_organization_url]]</organizationUrl>
<timezone>Europe/Paris</timezone>
<roles>
<role>[[author_role]]</role>
</roles>
</contributor>
</contributors>
<!-- Project eco-system definition -->
<organization>
<url>[[organization_url]]</url>
<name>[[organization_name]]</name>
</organization>
<scm>
<url>https://[[repo_git_hostname]]/[[repo_git_username]]/${project.name}</url>
<connection>scm:git:https://[[repo_git_hostname]]/[[repo_git_username]]/${project.name}.git</connection>
<developerConnection>scm:git:https://[[repo_git_hostname]]/[[repo_git_username]]/${project.name}.git</developerConnection>
<tag>${project.version}</tag>
</scm>
<issueManagement>
<system>Github issues</system>
<url>https://[[repo_git_hostname]]/[[repo_git_username]]/${project.name}/issues</url>
</issueManagement>
<ciManagement>
<url>https://travis-ci.org/[[repo_git_username]]/${project.name}</url>
<system>Travis-CI</system>
</ciManagement>
<properties>
<mainClass>[[project_mainclass]]</mainClass>
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
<github.global.server>github</github.global.server>
<!-- version eye user key -->
<versioneye.projectId>[[version_eye_user_key]]</versioneye.projectId>
</properties>
<!-- Project Dependencies -->
<dependencies>
<!-- JSON parsing -->
<!-- https://mvnrepository.com/artifact/com.jayway.jsonpath/json-path -->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.4.0</version>
</dependency>
<!-- SLF4J logger library -->
<!-- https://mvnrepository.com/artifact/org.slf4j/log4j-over-slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
<!-- Command line interface -->
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
<!-- Audio and Music system -->
<!-- https://mvnrepository.com/artifact/com.googlecode.soundlibs/jlayer -->
<dependency>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>jlayer</artifactId>
<version>1.0.1-2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.soundlibs/mp3spi -->
<dependency>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>mp3spi</artifactId>
<version>1.9.5-2</version>
</dependency>
<!-- TileMap loader Library -->
<!-- https://mvnrepository.com/artifact/org.mapeditor/libtiled -->
<dependency>
<groupId>org.mapeditor</groupId>
<artifactId>libtiled</artifactId>
<version>0.17</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
<source>1.8</source>
<target>1.8</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
<!-- Build the minimalist JAR without dependencies (Normal Edition) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
<encoding>utf-8</encoding>
</configuration>
</plugin>
<!-- Package a jar with Sources -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<enconding>utf-8</enconding>
</configuration>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Prepare Javadoc with a specific Markdown docklet -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<enconding>utf-8</enconding>
<stylesheet>maven</stylesheet>
<overview>${project.basedir}/README.md</overview>
<doclet>ch.raffael.doclets.pegdown.PegdownDoclet</doclet>
<docletArtifact>
<groupId>ch.raffael.pegdown-doclet</groupId>
<artifactId>pegdown-doclet</artifactId>
<version>1.1</version>
</docletArtifact>
<useStandardDocletOptions>true</useStandardDocletOptions>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Package a One full of dependencies JAR (Buffed Edition) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<encoding>utf-8</encoding>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-my-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- run class from maven -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>${mainClass}</mainClass>
<arguments>
<!-- to be soon interpreted by a CLI impl. -->
<argument>-d=1</argument>
<argument>-w=320</argument>
<argument>-h=240</argument>
<argument>-s=2</argument>
</arguments>
</configuration>
</plugin>
<!-- Build executable from jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<!-- put your configurations here -->
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainClass}</mainClass>
</transformer>
<!--transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>src/main/resources/res</resource> <file>options.properties</file>
</transformer -->
</transformers>
<!-- end of config -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- create a Windows EXE -->
<!-- https://[[repo_git_hostname]]/lukaszlenart/launch4j-maven-plugin/blob/master/src/main/resources/README.adoc -->
<!-- see http://launch4j.sourceforge.net/ -->
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.21</version>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<jar>${project.build.directory}/${artifactId}-${version}-shaded.jar</jar>
<outfile>${project.build.directory}/${project.name}.exe</outfile>
<downloadUrl>http://java.com/download</downloadUrl>
<classPath>
<mainClass>${mainClass}</mainClass>
<preCp>anything</preCp>
</classPath>
<icon>src/main/resources/res/gdj-application.ico</icon>
<jre>
<minVersion>1.8.0</minVersion>
<jdkPreference>preferJre</jdkPreference>
</jre>
<versionInfo>
<fileVersion>${project.version}</fileVersion>
<txtFileVersion>${project.version}</txtFileVersion>
<fileDescription>${project.name}</fileDescription>
<copyright>${project.inceptionYear} ${project.organization.name}</copyright>
<productVersion>${project.version}</productVersion>
<txtProductVersion>${project.version}</txtProductVersion>
<productName>${project.name}</productName>
<companyName>${project.organization.name}</companyName>
<internalName>${project.name}</internalName>
<originalFilename>${project.name}.exe</originalFilename>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
<!-- Publish artifacts to a specific repo-path to provide a temporary
Maven repository. -->
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<altDeploymentRepository>internal.repo::default::file://${project.build.directory}/mvn-repo</altDeploymentRepository>
</configuration>
</plugin>
<!-- Publish repo-path to a specific branch on github to provide a temporary
Maven repository. -->
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.12</version>
<configuration>
<message>Maven artifacts for ${project.version}</message> <!-- git commit message -->
<noJekyll>true</noJekyll> <!-- disable webpage processing -->
<outputDirectory>${project.build.directory}/mvn-repo</outputDirectory> <!-- matches distribution management repository url above -->
<branch>refs/heads/mvn-repo</branch> <!-- remote branch name -->
<includes>
<include>**/*</include>
</includes>
<repositoryName>${project.name}</repositoryName> <!-- github repo name -->
<repositoryOwner>[[repo_git_username]]</repositoryOwner> <!-- github username -->
</configuration>
<executions>
<!-- run site-maven-plugin's 'site' target as part of the build's normal
'deploy' phase -->
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
<!-- License attacher -->
<!-- see http://www.mojohaus.org/license-maven-plugin/examples/update-file-header-config.html -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>1.14</version>
<configuration>
<addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
<licenseFile>${project.basedir}/src/COPYING</licenseFile>
<licenseName>[[project_license]]</licenseName>
<thirdPartyFilename>LICENSE</thirdPartyFilename>
</configuration>
<executions>
<execution>
<id>update-file-header</id>
<goals>
<goal>update-file-header</goal>
</goals>
<phase>process-sources</phase>
</execution>
<execution>
<id>download-licenses</id>
<goals>
<goal>download-licenses</goal>
</goals>
<phase>prepare-package</phase>
</execution>
<execution>
<id>add-third-party</id>
<goals>
<goal>add-third-party</goal>
</goals>
<phase>prepare-package</phase>
</execution>
</executions>
</plugin>
<!-- Version Eye Dependencies survey -->
<plugin>
<groupId>com.versioneye</groupId>
<artifactId>versioneye-maven-plugin</artifactId>
<version>3.11.4</version>
<configuration>
<projectId>${versioneye.projectId}</projectId>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>Temporary Staging Repository</name>
<url>file://${project.build.directory}/mvn-repo</url>
</repository>
</distributionManagement>
</project>
# Properties to configure porject's files.
files=pom.xml,README.md
project.group=com.snapgames.gdj.prototypes
project.artifact=game101
project.version=0.0.1-SNAPSHOT
project.name=Game-101
project.description='A sample projet to illustrate basic of Game development.'
author.org.name=SnapGames
author.org.url=https://snapgames.github.io/
author.name='Frédéric Delorme'
author.email='frederic.delorme@snapgames.fr'
author.role=dev
repo.name=game-101
repo.owner=snapgames
repo.branch=develop
java.main.class=com.snapgames.gdj.prototype.game101.Game
versioneye.project.id=VPID101
@mcgivrer
Copy link
Author

mcgivrer commented Nov 19, 2017

The Ultimate Maven Project kit

What's inside ?

This incredible files project bundle offers a clear template for a brand new Java maven project, ready to import in Eclipse or IntelliJ; the .gitignore file has been prepared for.
It will be also ready to build on bitbucket-pipelines and travis-ci online free services.
And a template for README.md file drives the userdev to provide a full featured explaination on how to build and run this project.

plugins are prepared to build, package, a simple jar, a full jar with dependecies, add sources, add javadoc, produce the web site build a windows executable, verify dependencies updated version, and add some open source License to all files at package time.

And finally, some default dependencies are provided:

  • logging with SLF4J,
  • Apache common CLI to parse command line,
  • music, sound width some google libraries
  • and tilemap libraries

All those are referenced, to build any Java game :)

What to do ?

You will have to replace the following [[tags]] by your own values:

  1. All project's things :

    • [[project_groupid]] the maven GroupId of the porject
    • [[project_artifactid]] the maven ArtifactId of the project
    • [[project_name]] the name of the project
    • [[project_description]] the description of the project
    • [[project_year]] the inception year of the project
    • [[project_mainclass]] the main java class of the project to set the entry point at execution time
  2. Some specific project's things :

    • [[version_eye_user_key]] the specific VersoinEye user API key
    • [[project_license]] the prefered license to add the license template at top files
  3. All author's things:

    • [[author_name]] the author's name
    • [[author_email]] the author's email
    • [[author_organization]] the author's organization
    • [[author_organization_url]] the author's organization url
    • [[author_role]] the author's role on the project
  4. all about organization :

    • [[organization_name]] the organization's name
    • [[organization_url]] the organization's url
  5. all about the git repository :

    • [[repo_git_hostname]] the host of the git repository
    • [[repo_git_username]] the proprietary username for this git repository

That's all folks !

McG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment