Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
ffca60d3
Commit
ffca60d3
authored
Nov 22, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Rework BootRun so that it does not subclass JavaExec"
This reverts commit
6eee9de3
. Closes gh-10872
parent
6f97bc58
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
39 additions
and
285 deletions
+39
-285
running.adoc
.../spring-boot-gradle-plugin/src/main/asciidoc/running.adoc
+11
-15
application-plugin-main-class-name.gradle
.../gradle/running/application-plugin-main-class-name.gradle
+1
-1
boot-run-custom-exec-spec.gradle
.../src/main/gradle/running/boot-run-custom-exec-spec.gradle
+0
-16
boot-run-main.gradle
...radle-plugin/src/main/gradle/running/boot-run-main.gradle
+2
-2
spring-boot-dsl-main-class-name.gradle
...ain/gradle/running/spring-boot-dsl-main-class-name.gradle
+1
-1
JavaPluginAction.java
.../springframework/boot/gradle/plugin/JavaPluginAction.java
+5
-6
MainClassConvention.java
...ringframework/boot/gradle/plugin/MainClassConvention.java
+3
-3
BootRun.java
...va/org/springframework/boot/gradle/tasks/run/BootRun.java
+13
-150
BootRunApplication.java
...-plugin/src/test/java/com/example/BootRunApplication.java
+0
-15
RunningDocumentationTests.java
...framework/boot/gradle/docs/RunningDocumentationTests.java
+0
-7
BootRunIntegrationTests.java
...mework/boot/gradle/tasks/run/BootRunIntegrationTests.java
+0
-27
BootRunIntegrationTests-applicationPluginMainClassNameIsNotUsedWhenItIsNull.gradle
...pplicationPluginMainClassNameIsNotUsedWhenItIsNull.gradle
+1
-1
BootRunIntegrationTests-applicationPluginMainClassNameIsUsed.gradle
...egrationTests-applicationPluginMainClassNameIsUsed.gradle
+1
-1
BootRunIntegrationTests-argsCanBeConfigured.gradle
...ks/run/BootRunIntegrationTests-argsCanBeConfigured.gradle
+0
-12
BootRunIntegrationTests-execSpecCanBeConfigured.gradle
...un/BootRunIntegrationTests-execSpecCanBeConfigured.gradle
+0
-15
BootRunIntegrationTests-jvmArgsCanBeConfigured.gradle
...run/BootRunIntegrationTests-jvmArgsCanBeConfigured.gradle
+0
-12
BootRunIntegrationTests-springBootExtensionMainClassNameIsUsed.gradle
...rationTests-springBootExtensionMainClassNameIsUsed.gradle
+1
-1
No files found.
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/asciidoc/running.adoc
View file @
ffca60d3
...
...
@@ -8,11 +8,16 @@ To run your application without first building an archive use the `bootRun` task
$ ./gradlew bootRun
----
The `bootRun` task is automatically configured to use the runtime classpath of the
main source set. By default, the main class will be discovered by looking for a class
with a `public static void main(String[])` method in directories on the task's
classpath. The main class can also be configured explicitly using the task's
`mainClassName` property:
The `bootRun` task is an instance of
{boot-run-javadoc}[`BootRun`] which is a `JavaExec` subclass. As such, all of the
{gradle-dsl}/org.gradle.api.tasks.JavaExec.html[usual configuration options] for executing
a Java process in Gradle are available to you. The task is automatically configured to use
the runtime classpath of the main source set.
By default, the main class will be configured automatically by looking for a class with a
`public static void main(String[])` method in directories on the task's classpath.
The main class can also be configured explicitly using the task's `main` property:
[source,groovy,indent=0,subs="verbatim"]
----
...
...
@@ -27,7 +32,7 @@ Alternatively, the main class name can be configured project-wide using the
include::../gradle/running/spring-boot-dsl-main-class-name.gradle[tags=main-class]
----
If the {application-plugin}[`application` plugin] has been applied its `mainClassName`
If the {application-plugin}[`application` plugin] has been applied
,
its `mainClassName`
project property can be used for the same purpose:
[source,groovy,indent=0,subs="verbatim"]
...
...
@@ -35,15 +40,6 @@ project property can be used for the same purpose:
include::../gradle/running/application-plugin-main-class-name.gradle[tags=main-class]
----
Two properties, `args` and `jvmArgs`, are also provided for configuring the
arguments and JVM arguments that are used to run the application.
For more advanced configuration the `JavaExecSpec` that is used can be customized:
[source,groovy,indent=0,subs="verbatim"]
----
include::../gradle/running/boot-run-custom-exec-spec.gradle[tags=customization]
----
[[running-your-application-reloading-resources]]
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/running/application-plugin-main-class-name.gradle
View file @
ffca60d3
...
...
@@ -14,6 +14,6 @@ mainClassName = 'com.example.ExampleApplication'
task
configuredMainClass
{
doLast
{
println
bootRun
.
main
ClassName
println
bootRun
.
main
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/running/boot-run-custom-exec-spec.gradle
deleted
100644 → 0
View file @
6f97bc58
buildscript
{
dependencies
{
classpath
files
(
pluginClasspath
.
split
(
','
))
}
}
apply
plugin:
'org.springframework.boot'
apply
plugin:
'java'
// tag::customization[]
bootRun
{
execSpec
{
systemProperty
'com.example.foo'
,
'bar'
}
}
// end::customization[]
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/running/boot-run-main.gradle
View file @
ffca60d3
...
...
@@ -9,12 +9,12 @@ apply plugin: 'java'
// tag::main[]
bootRun
{
main
ClassName
=
'com.example.ExampleApplication'
main
=
'com.example.ExampleApplication'
}
// end::main[]
task
configuredMainClass
{
doLast
{
println
bootRun
.
main
ClassName
println
bootRun
.
main
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/gradle/running/spring-boot-dsl-main-class-name.gradle
View file @
ffca60d3
...
...
@@ -16,6 +16,6 @@ springBoot {
task
configuredMainClass
{
doLast
{
println
bootRun
.
main
ClassName
println
bootRun
.
main
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java
View file @
ffca60d3
...
...
@@ -102,7 +102,6 @@ final class JavaPluginAction implements PluginApplicationAction {
this
.
singlePublishedArtifact
.
addCandidate
(
artifact
);
}
@SuppressWarnings
(
"unchecked"
)
private
void
configureBootRunTask
(
Project
project
)
{
JavaPluginConvention
javaConvention
=
project
.
getConvention
()
.
getPlugin
(
JavaPluginConvention
.
class
);
...
...
@@ -111,14 +110,14 @@ final class JavaPluginAction implements PluginApplicationAction {
run
.
setGroup
(
ApplicationPlugin
.
APPLICATION_GROUP
);
run
.
classpath
(
javaConvention
.
getSourceSets
()
.
findByName
(
SourceSet
.
MAIN_SOURCE_SET_NAME
).
getRuntimeClasspath
());
run
.
setJvmArgs
(
project
.
provider
(
()
->
{
run
.
getConventionMapping
().
map
(
"jvmArgs"
,
()
->
{
if
(
project
.
hasProperty
(
"applicationDefaultJvmArgs"
))
{
return
(
List
<
String
>)
project
.
property
(
"applicationDefaultJvmArgs"
);
return
project
.
property
(
"applicationDefaultJvmArgs"
);
}
return
Collections
.
emptyList
();
})
)
;
run
.
setMainClassName
(
project
.
provider
(
new
MainClassConvention
(
project
,
run:
:
getClasspath
)
));
});
run
.
conventionMapping
(
"main"
,
new
MainClassConvention
(
project
,
run:
:
getClasspath
));
}
private
void
configureUtf8Encoding
(
Project
project
)
{
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/MainClassConvention.java
View file @
ffca60d3
...
...
@@ -33,7 +33,7 @@ import org.springframework.boot.loader.tools.MainClassFinder;
*
* @author Andy Wilkinson
*/
final
class
MainClassConvention
implements
Callable
<
String
>
{
final
class
MainClassConvention
implements
Callable
<
Object
>
{
private
static
final
String
SPRING_BOOT_APPLICATION_CLASS_NAME
=
"org.springframework.boot.autoconfigure.SpringBootApplication"
;
...
...
@@ -47,7 +47,7 @@ final class MainClassConvention implements Callable<String> {
}
@Override
public
String
call
()
throws
Exception
{
public
Object
call
()
throws
Exception
{
SpringBootExtension
springBootExtension
=
this
.
project
.
getExtensions
()
.
findByType
(
SpringBootExtension
.
class
);
if
(
springBootExtension
!=
null
...
...
@@ -57,7 +57,7 @@ final class MainClassConvention implements Callable<String> {
if
(
this
.
project
.
hasProperty
(
"mainClassName"
))
{
Object
mainClassName
=
this
.
project
.
property
(
"mainClassName"
);
if
(
mainClassName
!=
null
)
{
return
mainClassName
.
toString
()
;
return
mainClassName
;
}
}
return
resolveMainClass
();
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/run/BootRun.java
View file @
ffca60d3
...
...
@@ -16,21 +16,10 @@
package
org
.
springframework
.
boot
.
gradle
.
tasks
.
run
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.gradle.api.Action
;
import
org.gradle.api.DefaultTask
;
import
org.gradle.api.file.FileCollection
;
import
org.gradle.api.file.SourceDirectorySet
;
import
org.gradle.api.provider.PropertyState
;
import
org.gradle.api.provider.Provider
;
import
org.gradle.api.tasks.InputFiles
;
import
org.gradle.api.tasks.JavaExec
;
import
org.gradle.api.tasks.SourceSet
;
import
org.gradle.api.tasks.SourceSetOutput
;
import
org.gradle.api.tasks.TaskAction
;
import
org.gradle.process.JavaExecSpec
;
/**
* Custom {@link JavaExec} task for running a Spring Boot application.
...
...
@@ -38,35 +27,7 @@ import org.gradle.process.JavaExecSpec;
* @author Andy Wilkinson
* @since 2.0.0
*/
public
class
BootRun
extends
DefaultTask
{
private
final
PropertyState
<
String
>
mainClassName
=
getProject
()
.
property
(
String
.
class
);
@SuppressWarnings
(
"unchecked"
)
private
final
PropertyState
<
List
<
String
>>
jvmArgs
=
(
PropertyState
<
List
<
String
>>)
(
Object
)
getProject
()
.
property
(
List
.
class
);
@SuppressWarnings
(
"unchecked"
)
private
final
PropertyState
<
List
<
String
>>
args
=
(
PropertyState
<
List
<
String
>>)
(
Object
)
getProject
()
.
property
(
List
.
class
);
private
FileCollection
classpath
=
getProject
().
files
();
private
List
<
Action
<
JavaExecSpec
>>
execSpecConfigurers
=
new
ArrayList
<>();
/**
* Adds the given {@code entries} to the classpath used to run the application.
* @param entries the classpath entries
*/
public
void
classpath
(
Object
...
entries
)
{
this
.
classpath
=
this
.
classpath
.
plus
(
getProject
().
files
(
entries
));
}
@InputFiles
public
FileCollection
getClasspath
()
{
return
this
.
classpath
;
}
public
class
BootRun
extends
JavaExec
{
/**
* Adds the {@link SourceDirectorySet#getSrcDirs() source directories} of the given
...
...
@@ -77,116 +38,18 @@ public class BootRun extends DefaultTask {
* @param sourceSet the source set
*/
public
void
sourceResources
(
SourceSet
sourceSet
)
{
this
.
classpath
=
getProject
()
.
files
(
sourceSet
.
getResources
().
getSrcDirs
(),
this
.
classpath
)
.
filter
((
file
)
->
!
file
.
equals
(
sourceSet
.
getOutput
().
getResourcesDir
()));
}
/**
* Returns the name of the main class to be run.
* @return the main class name or {@code null}
*/
public
String
getMainClassName
()
{
return
this
.
mainClassName
.
getOrNull
();
}
/**
* Sets the name of the main class to be executed using the given
* {@code mainClassNameProvider}.
*
* @param mainClassNameProvider provider of the main class name
*/
public
void
setMainClassName
(
Provider
<
String
>
mainClassNameProvider
)
{
this
.
mainClassName
.
set
(
mainClassNameProvider
);
}
/**
* Sets the name of the main class to be run.
*
* @param mainClassName the main class name
*/
public
void
setMainClassName
(
String
mainClassName
)
{
this
.
mainClassName
.
set
(
mainClassName
);
}
/**
* Returns the JVM arguments to be used to run the application.
* @return the JVM arguments or {@code null}
*/
public
List
<
String
>
getJvmArgs
()
{
return
this
.
jvmArgs
.
getOrNull
();
}
/**
* Configures the application to be run using the JVM args provided by the given
* {@code jvmArgsProvider}.
*
* @param jvmArgsProvider the provider of the JVM args
*/
public
void
setJvmArgs
(
Provider
<
List
<
String
>>
jvmArgsProvider
)
{
this
.
jvmArgs
.
set
(
jvmArgsProvider
);
}
/**
* Configures the application to be run using the given {@code jvmArgs}.
* @param jvmArgs the JVM args
*/
public
void
setJvmArgs
(
List
<
String
>
jvmArgs
)
{
this
.
jvmArgs
.
set
(
jvmArgs
);
}
/**
* Returns the arguments to be used to run the application.
* @return the arguments or {@code null}
*/
public
List
<
String
>
getArgs
()
{
return
this
.
args
.
getOrNull
();
}
/**
* Configures the application to be run using the given {@code args}.
* @param args the args
*/
public
void
setArgs
(
List
<
String
>
args
)
{
this
.
args
.
set
(
args
);
}
/**
* Configures the application to be run using the args provided by the given
* {@code argsProvider}.
* @param argsProvider the provider of the args
*/
public
void
setArgs
(
Provider
<
List
<
String
>>
argsProvider
)
{
this
.
args
.
set
(
argsProvider
);
}
/**
* Registers the given {@code execSpecConfigurer} to be called to customize the
* {@link JavaExecSpec} prior to running the application.
* @param execSpecConfigurer the configurer
*/
public
void
execSpec
(
Action
<
JavaExecSpec
>
execSpecConfigurer
)
{
this
.
execSpecConfigurers
.
add
(
execSpecConfigurer
);
}
@TaskAction
public
void
run
()
{
getProject
().
javaexec
((
spec
)
->
{
spec
.
classpath
(
this
.
classpath
);
spec
.
setMain
(
this
.
mainClassName
.
getOrNull
());
if
(
this
.
jvmArgs
.
isPresent
())
{
spec
.
setJvmArgs
(
this
.
jvmArgs
.
get
());
}
if
(
this
.
args
.
isPresent
())
{
spec
.
setArgs
(
this
.
args
.
get
());
}
if
(
System
.
console
()
!=
null
)
{
// Record that the console is available here for AnsiOutput to detect
// later
spec
.
environment
(
"spring.output.ansi.console-available"
,
true
);
}
this
.
execSpecConfigurers
.
forEach
((
configurer
)
->
configurer
.
execute
(
spec
));
});
setClasspath
(
getProject
()
.
files
(
sourceSet
.
getResources
().
getSrcDirs
(),
getClasspath
())
.
filter
((
file
)
->
!
file
.
equals
(
sourceSet
.
getOutput
().
getResourcesDir
())));
}
@Override
public
void
exec
()
{
if
(
System
.
console
()
!=
null
)
{
// Record that the console is available here for AnsiOutput to detect later
this
.
getEnvironment
().
put
(
"spring.output.ansi.console-available"
,
true
);
}
super
.
exec
();
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/com/example/BootRunApplication.java
View file @
ffca60d3
...
...
@@ -18,7 +18,6 @@ package com.example;
import
java.io.File
;
import
java.lang.management.ManagementFactory
;
import
java.util.Arrays
;
/**
* Very basic application used for testing {@code BootRun}.
...
...
@@ -32,12 +31,6 @@ public class BootRunApplication {
}
public
static
void
main
(
String
[]
args
)
{
dumpClassPath
();
dumpArgs
(
args
);
dumpJvmArgs
();
}
private
static
void
dumpClassPath
()
{
int
i
=
1
;
for
(
String
entry
:
ManagementFactory
.
getRuntimeMXBean
().
getClassPath
()
.
split
(
File
.
pathSeparator
))
{
...
...
@@ -45,12 +38,4 @@ public class BootRunApplication {
}
}
private
static
void
dumpArgs
(
String
[]
args
)
{
System
.
out
.
println
(
Arrays
.
toString
(
args
));
}
private
static
void
dumpJvmArgs
()
{
System
.
out
.
println
(
ManagementFactory
.
getRuntimeMXBean
().
getInputArguments
());
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/docs/RunningDocumentationTests.java
View file @
ffca60d3
...
...
@@ -67,11 +67,4 @@ public class RunningDocumentationTests {
.
contains
(
new
File
(
"src/main/resources"
).
getPath
());
}
@Test
public
void
bootRunExecSpecCustomization
()
throws
IOException
{
this
.
gradleBuild
.
script
(
"src/main/gradle/running/boot-run-custom-exec-spec.gradle"
)
.
build
();
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests.java
View file @
ffca60d3
...
...
@@ -56,33 +56,6 @@ public class BootRunIntegrationTests {
.
doesNotContain
(
canonicalPathOf
(
"src/main/resources"
));
}
@Test
public
void
argsCanBeConfigured
()
throws
IOException
{
copyApplication
();
new
File
(
this
.
gradleBuild
.
getProjectDir
(),
"src/main/resources"
).
mkdirs
();
BuildResult
result
=
this
.
gradleBuild
.
build
(
"bootRun"
);
assertThat
(
result
.
task
(
":bootRun"
).
getOutcome
()).
isEqualTo
(
TaskOutcome
.
SUCCESS
);
assertThat
(
result
.
getOutput
()).
contains
(
"--com.example.foo=bar"
);
}
@Test
public
void
jvmArgsCanBeConfigured
()
throws
IOException
{
copyApplication
();
new
File
(
this
.
gradleBuild
.
getProjectDir
(),
"src/main/resources"
).
mkdirs
();
BuildResult
result
=
this
.
gradleBuild
.
build
(
"bootRun"
);
assertThat
(
result
.
task
(
":bootRun"
).
getOutcome
()).
isEqualTo
(
TaskOutcome
.
SUCCESS
);
assertThat
(
result
.
getOutput
()).
contains
(
"-Dcom.example.foo=bar"
);
}
@Test
public
void
execSpecCanBeConfigured
()
throws
IOException
{
copyApplication
();
new
File
(
this
.
gradleBuild
.
getProjectDir
(),
"src/main/resources"
).
mkdirs
();
BuildResult
result
=
this
.
gradleBuild
.
build
(
"bootRun"
);
assertThat
(
result
.
task
(
":bootRun"
).
getOutcome
()).
isEqualTo
(
TaskOutcome
.
SUCCESS
);
assertThat
(
result
.
getOutput
()).
contains
(
"-Dcom.example.foo=bar"
);
}
@Test
public
void
sourceResourcesCanBeUsed
()
throws
IOException
{
copyApplication
();
...
...
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-applicationPluginMainClassNameIsNotUsedWhenItIsNull.gradle
View file @
ffca60d3
...
...
@@ -10,6 +10,6 @@ apply plugin: 'org.springframework.boot'
task
echoMainClassName
{
dependsOn
compileJava
doLast
{
println
'Main class name = '
+
bootRun
.
main
ClassName
println
'Main class name = '
+
bootRun
.
main
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-applicationPluginMainClassNameIsUsed.gradle
View file @
ffca60d3
...
...
@@ -10,5 +10,5 @@ apply plugin: 'org.springframework.boot'
mainClassName
=
'com.example.CustomMainClass'
task
echoMainClassName
{
println
'Main class name = '
+
bootRun
.
main
ClassName
println
'Main class name = '
+
bootRun
.
main
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-argsCanBeConfigured.gradle
deleted
100644 → 0
View file @
6f97bc58
buildscript
{
dependencies
{
classpath
files
(
pluginClasspath
.
split
(
','
))
}
}
apply
plugin:
'java'
apply
plugin:
'org.springframework.boot'
bootRun
{
args
=
[
'--com.example.foo=bar'
]
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-execSpecCanBeConfigured.gradle
deleted
100644 → 0
View file @
6f97bc58
buildscript
{
dependencies
{
classpath
files
(
pluginClasspath
.
split
(
','
))
}
}
apply
plugin:
'java'
apply
plugin:
'org.springframework.boot'
bootRun
{
execSpec
{
systemProperty
'com.example.foo'
,
'bar'
}
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-jvmArgsCanBeConfigured.gradle
deleted
100644 → 0
View file @
6f97bc58
buildscript
{
dependencies
{
classpath
files
(
pluginClasspath
.
split
(
','
))
}
}
apply
plugin:
'java'
apply
plugin:
'org.springframework.boot'
bootRun
{
jvmArgs
=
[
'-Dcom.example.foo=bar'
]
}
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/run/BootRunIntegrationTests-springBootExtensionMainClassNameIsUsed.gradle
View file @
ffca60d3
...
...
@@ -12,5 +12,5 @@ springBoot {
}
task
echoMainClassName
{
println
'Main class name = '
+
bootRun
.
main
ClassName
println
'Main class name = '
+
bootRun
.
main
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment