Am new to docker and am trying out containerization for the first time.
Have seen Java projects on Github that developers have setup as both gradle and maven projects.
Created the following project structure:
HelloDocker
│
├── Dockerfile
├── README.md
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── mvnw
├── mvnw.cmd
├── pom.xml
├── settings.gradle
└── src
├── main
│ ├── java
│ │ └── com
│ │ └── hellodocker
│ │ ├── HelloDockerApplication.java
│ │ ├── controller
│ │ │ └── HelloController.java
│ │ └── model
│ │ └── User.java
│ └── resources
│ ├── application.properties
│ ├── static
│ └── templates
└── test
└── java
└── com
└── hellodocker
└── HelloDockerApplicationTests.java
Maven 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hellodocker</groupId>
<artifactId>hellodocker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>hellodocker</name>
<description>Spring Boot Docker Example</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.hellodocker'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
Dockerfile:
FROM openjdk:11
VOLUME /tmp
ADD target/hellodocker-0.0.1-SNAPSHOT.jar hellodocker-app.jar
ENTRYPOINT ["java", "-jar", "/hellodocker-app.jar" ]
As you can see, this relies on the project being built into a jar file from maven (because of the target
directory dependency on line 3 (gradle builds rely/depend on a build/lib
directory.
Question(s):
Is possible to set up the Dockerfile to accommodate both types of build scripts?
Is it a bad practice (e.g. for from a DevOps continuous integration standpoint) to rely on two build script? For example, should Java projects that will be deployed on CircularCI, Jenkins, Travis and / or GitLab rely only one type of build script DSL?
The reason I wish to use both is so future developers who access my projects can be comfortable with choosing either gradle or maven (of course, this creates the hassle of maintaining two different build scripts, in the future)...