Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions spring-boot-project/spring-boot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
<versions-maven-plugin.version>2.7</versions-maven-plugin.version>
<xml-maven-plugin.version>1.0.2</xml-maven-plugin.version>
<flatten-maven-plugin.version>1.1.0</flatten-maven-plugin.version>
<maven-toolchains-plugin.version>3.0.0</maven-toolchains-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -3349,6 +3350,11 @@
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>${maven-toolchains-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals=clean verify -t toolchains.xml
invoker.os.family=!windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo 'The Maven Toolchains is awesome!'
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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.boot.maven.it</groupId>
<artifactId>run-toolchains</artifactId>
<version>0.0.1.BUILD-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>@java.version@</maven.compiler.source>
<maven.compiler.target>@java.version@</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>@maven-toolchains-plugin.version@</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk/>
</toolchains>
</configuration>
</plugin>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.test;

public class SampleApplication {

public static void main(String[] args) {
throw new IllegalStateException("Should not be called!");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<toolchains>
<toolchain>
<type>jdk</type>
<configuration>
<jdkHome>jdkHome</jdkHome>
</configuration>
</toolchain>
</toolchains>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def file = new File(basedir, "build.log")
return file.text.contains("The Maven Toolchains is awesome!")

Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@
import java.util.stream.Collectors;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactFeatureFilter;
import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;

import org.springframework.boot.loader.tools.FileUtils;
import org.springframework.boot.loader.tools.JavaExecutable;
import org.springframework.boot.loader.tools.MainClassFinder;

/**
Expand Down Expand Up @@ -196,6 +201,20 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
@Parameter(property = "spring-boot.run.skip", defaultValue = "false")
private boolean skip;

/**
* The Maven Session Object.
* @since 2.2.1
*/
@Parameter(defaultValue = "${session}", readonly = true)
private MavenSession session;

/**
* The toolchain manager to use.
* @since 2.2.1
*/
@Component
private ToolchainManager toolchainManager;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (this.skip) {
Expand Down Expand Up @@ -316,6 +335,16 @@ protected RunArguments resolveApplicationArguments() {
return runArguments;
}

/**
* Provides access to the java binary executable, regardless of OS.
* @return the java executable
**/
protected String getJavaExecutable() {
Toolchain toolchain = this.toolchainManager.getToolchainFromBuildContext("jdk", this.session);
String javaExecutable = (toolchain != null) ? toolchain.findTool("java") : null;
return (javaExecutable != null) ? javaExecutable : new JavaExecutable().toString();
}

/**
* Resolve the environment variables to use.
* @return an {@link EnvVariables} defining the environment variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

import org.springframework.boot.loader.tools.JavaExecutable;
import org.springframework.boot.loader.tools.RunProcess;

/**
Expand Down Expand Up @@ -111,7 +110,7 @@ protected void runWithForkedJvm(File workingDirectory, List<String> args, Map<St
private int forkJvm(File workingDirectory, List<String> args, Map<String, String> environmentVariables)
throws MojoExecutionException {
try {
RunProcess runProcess = new RunProcess(workingDirectory, new JavaExecutable().toString());
RunProcess runProcess = new RunProcess(workingDirectory, getJavaExecutable());
Runtime.getRuntime().addShutdownHook(new Thread(new RunProcessKiller(runProcess)));
return runProcess.run(true, args, environmentVariables);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;

import org.springframework.boot.loader.tools.JavaExecutable;
import org.springframework.boot.loader.tools.RunProcess;

/**
Expand Down Expand Up @@ -104,7 +103,7 @@ protected void runWithForkedJvm(File workingDirectory, List<String> args, Map<St
private RunProcess runProcess(File workingDirectory, List<String> args, Map<String, String> environmentVariables)
throws MojoExecutionException {
try {
RunProcess runProcess = new RunProcess(workingDirectory, new JavaExecutable().toString());
RunProcess runProcess = new RunProcess(workingDirectory, getJavaExecutable());
runProcess.run(false, args, environmentVariables);
return runProcess;
}
Expand Down