Skip to content

Instantly share code, notes, and snippets.

@mcgivrer
Last active February 23, 2023 04:23
Show Gist options
  • Save mcgivrer/1aad56cc0d0bed3bbe53dc10a2714ca8 to your computer and use it in GitHub Desktop.
Save mcgivrer/1aad56cc0d0bed3bbe53dc10a2714ca8 to your computer and use it in GitHub Desktop.
Standard Java desktop maven project with a pom.xml file, a README.md, and some Continuous integration configuration files (AppVeyor and Travis-CI, more to come...)
target/
.project
.classpath
.settings/
language: java
jdk:
- oraclejdk8
before_install:
- Commands to execute before install

[PROJECT_NAME]

AppVeyor (win32) Build status Travis-CI (linux) Build Status Dependency Status

Introduction

TODO

Project structure

The maven project is mostly standard:

[PROJECT_NAME]/
 |_ src
 |  |_ main 
 |  |  |_ java 
 |  |  |_ resources 
 |  |_ test 
 |  |  |_ java 
 |  |  |_ resources 
 |_ .gitignore
 |_ .travis.yml
 |_ appveyor.yml
 |_ bitbucket-pipelines.yml
 |_ pom.xml
 |_ README.md

Bellow the satandard pom.xml file, the Continuous integration files are :

  • appveyor.yml
  • bitbucket.org

Compile

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

    $> mvn clean install

Execute the program

  • 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

Publish as a 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>

References

[AUTHOR_NAME]

version: '{build}'
os: Windows Server 2012
install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\maven" )) {
(new-object System.Net.WebClient).DownloadFile(
'http://www.us.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip',
'C:\maven-bin.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
}
- cmd: SET PATH=C:\maven\apache-maven-3.3.9\bin;%JAVA_HOME%\bin;%PATH
- cmd: SET MAVEN_OPTS=-XX:MaxPermSize=2g -Xmx4g
- cmd: SET JAVA_OPTS=-XX:MaxPermSize=2g -Xmx4g
build_script:
- mvn clean package --batch-mode -DskipTest
test_script:
- mvn clean install --batch-mode
cache:
- C:\maven\
- C:\Users\appveyor\.m2
# File proposed by Bitbucket for the free pipelines.
# -----
# This is a sample build configuration for Java (Maven).
# Check our guides at https://confluence.atlassian.com/x/zd-5Mw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
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_GROUP]</groupId>
<artifactId>[PROJECT_ARTIFACT]</artifactId>
<version>[PROJECT_VERSION:0.0.1-SNAPSHOT]</version>
<name>[PROJECT_NAME]</name>
<description>[PROJECT_DESCRIPTION]</description>
<inception>2017</inception>
<properties>
<!-- Author details -->
<author.org.name>[AUTHOR_ORG_NAME]</author.org.name>
<author.org.url>[AUTHOR_ORG_URL]</author.org.url>
<author.name>[AUTHOR_NAME]</author.name>
<author.email>[AUTHOR_EMAIL]</author.email>
<author.role>[AUTHOR_ROLE:dev,devops,architect,etc...]</author.role>
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
<github.global.server>github</github.global.server>
<repo.name>[REPO_NAME:name of the github repository]</repo.name>
<repo.owner>[REPO_OWNER:owner of the github]</repo.owner>
<!-- Main Class to start the java dance -->
<mainClass>[JAVA_MAIN_CLASS:the main class where all start]</mainClass>
<versioneye.projectid>[VERSIONEYE_PROJECT_ID]</versioneye.projectid>
</properties>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
<organization>
<name>${author.org.name}</name>
<url>${author.org.url}</url>
</organization>
<scm>
<url>https://github.com/${repo.owner}/${repo.name}</url>
<connection>scm:git:git@github.com:${repo.owner}/${repo.name}.git</connection>
<developerConnection>scm:git:git@github.com:${repo.owner}/${repo.name}.git</developerConnection>
<tag>${project.version}</tag>
</scm>
<issueManagement>
<system>github.com</system>
<url>https://github.com/${repo.owner}/${repo.name}/issues</url>
</issueManagement>
<ciManagement>
<system>travis-ci</system>
<url>https://travis-ci.org/${repo.owner}/${repo.name}</url>
</ciManagement>
<contributors>
<contributor>
<name>${author.name}</name>
<email>${author.email}</email>
<organization>${author.org.name}</organization>
<organizationUrl>${author.org.url}</organizationUrl>
<timezone>Europe/Paris</timezone>
<roles>
<role>${author.role}</role>
</roles>
</contributor>
</contributors>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</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 and PlantUML 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>
<!-- see https://github.com/Abnaxos/markdown-doclet -->
<doclet>ch.raffael.mddoclet.MarkdownDoclet</doclet>
<docletArtifact>
<groupId>ch.raffael.markdown-doclet</groupId>
<artifactId>markdown-doclet</artifactId>
<version>1.4</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>2.6</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>
<!-- Prepare packaging to deploy artifact to 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>
<!-- Description and confguration of Github repository -->
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.12</version>
<configuration>
<encoding>utf-8</encoding>
<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>${repo.name}</repositoryName> <!-- github repo name -->
<repositoryOwner>${repo.owner}</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>
<!-- Version Eye Dependencies survey -->
<plugin>
<groupId>com.versioneye</groupId>
<artifactId>versioneye-maven-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<projectId>${versioneye.projectid}</projectId>
</configuration>
</plugin>
</plugins>
</build>
</project>
# Properties to configure project's files.
#-----------------------------------------
# list of files to be parsedfiles=pom.xml,README.md
# maven Groupd ID for your project
project.group=
# maven artifact Id for your project
project.artifact=
# maven version for your project
project.version=
# the name of your poject
project.name=
# a short description for your project
project.description=
# The Author's organization name
author.org.name=
# The Author's organization URL
author.org.url=
# the author's name
author.name=
# the author's email
author.email=
# the author's role for your maven project
author.role=
# the github project name (e.g. in http://git@github.com:owner/[REPO_NAME].git
repo.name=
# the github project name (e.g. in http://git@github.com:[REPO_OWNER]/reponame.git
repo.owner=
# the branch where to push to with mvn to repos.
repo.branch=
# the main class where all start with
java.main.class=
# the version_eye unique ID service (see https://versioneye.com/)
versioneye.project.id=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment