Skip to content

Instantly share code, notes, and snippets.

@fzn0x
Created February 16, 2024 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fzn0x/3b8da1c151ded6dc92dcadaed0866dc4 to your computer and use it in GitHub Desktop.
Save fzn0x/3b8da1c151ded6dc92dcadaed0866dc4 to your computer and use it in GitHub Desktop.
Gradle Configuration - Maven Configuration Comparison
plugins {
id 'org.springframework.boot' version '3.2.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '21'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
}
bootJar {
archiveFileName = "${project.name}.jar"
archiveVersion = ""
}
war {
exclude '**/WEB-INF/lib/*gson*.jar'
}
tasks.withType(org.springframework.boot.gradle.tasks.bundling.BootBuildImage).configureEach {
builder = 'jib'
}
task copyFrontendResources(type: Copy) {
from 'src/main/frontend/build/static'
into 'build/resources/main/static'
}
task copyFrontendBuild(type: Copy) {
from 'src/main/frontend/build'
into 'build/resources/main'
}
processResources.dependsOn copyFrontendResources, copyFrontendBuild
@fzn0x
Copy link
Author

fzn0x commented Feb 16, 2024

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>3.2.2</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>demo</name>
	<description>Demo project for Spring Boot</description>
	<properties>
		<java.version>21</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>
		</dependency>
		
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<optional>true</optional>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
	</dependencies>

	<build>
		<directory>${project.basedir}/target</directory>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<addResources>true</addResources>
				</configuration>
				<executions>
					<execution>
						<goals>
						<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
				<packagingExcludes>WEB-INF/lib/*gson*.jar</packagingExcludes>
				</configuration>
			</plugin>
			<plugin>
				<groupId>com.github.eirslett</groupId>
				<artifactId>frontend-maven-plugin</artifactId>
				<version>1.6</version>
				<configuration>
					<workingDirectory>src/main/frontend</workingDirectory>
					<installDirectory>target</installDirectory>
				</configuration>
				<executions>
					<execution>
					<id>install node and npm</id>
					<goals>
						<goal>install-node-and-npm</goal>
					</goals>
					<configuration>
						<nodeVersion>v18.16.0</nodeVersion>
						<npmVersion>10.4.0</npmVersion>
					</configuration>
					</execution>
					<execution>
					<id>npm install</id>
					<goals>
						<goal>npm</goal>
					</goals>
					<configuration>
						<arguments>install</arguments>
					</configuration>
					</execution>
					<execution>
					<id>npm run build</id>
					<goals>
						<goal>npm</goal>
					</goals>
					<configuration>
						<arguments>run build</arguments>
					</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>
					<execution>
						<phase>generate-resources</phase>
						<configuration>
						<target>
							<copy todir="${project.build.directory}/classes/static">
								<fileset dir="${project.basedir}/src/main/frontend/build/static" />
							</copy>
							<copy todir="${project.build.directory}/classes/static">
								<fileset dir="${project.basedir}/src/main/frontend/build" />
							</copy>
						</target>
					</configuration>
					<goals>
						<goal>run</goal>
					</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

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