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
fc463afb
Commit
fc463afb
authored
Mar 29, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
abd86e50
1043239d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
11 deletions
+52
-11
MainClassTests.java
.../java/org/springframework/boot/gradle/MainClassTests.java
+30
-5
main-class.gradle
...ng-boot-gradle-tests/src/test/resources/main-class.gradle
+9
-2
FindMainClassTask.java
...rg/springframework/boot/gradle/run/FindMainClassTask.java
+13
-4
No files found.
spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/MainClassTests.java
View file @
fc463afb
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
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.
...
...
@@ -18,30 +18,55 @@ package org.springframework.boot.gradle;
import
java.io.IOException
;
import
org.gradle.tooling.BuildException
;
import
org.gradle.tooling.ProjectConnection
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for configuring a project's main class
*
* @author Dave Syer
* @author Andy Wilkinson
*/
public
class
MainClassTests
{
private
static
ProjectConnection
project
;
private
static
final
String
BOOT_VERSION
=
Versions
.
getBootVersion
();
private
static
ProjectConnection
project
;
@BeforeClass
public
static
void
createProject
()
throws
IOException
{
project
=
new
ProjectCreator
().
createProject
(
"main-
in-boot-run
"
);
project
=
new
ProjectCreator
().
createProject
(
"main-
class
"
);
}
@Test
public
void
mainFromBootRun
()
{
project
.
newBuild
().
forTasks
(
"build"
)
.
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"--info"
).
run
();
.
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"-PbootRunMain=true"
)
.
run
();
}
@Test
public
void
nonJavaExecRunTaskIsIgnored
()
{
try
{
project
.
newBuild
().
forTasks
(
"build"
).
withArguments
(
"-PbootVersion="
+
BOOT_VERSION
,
"-PnonJavaExecRun=true"
).
run
();
}
catch
(
BuildException
ex
)
{
Throwable
rootCause
=
getRootCause
(
ex
);
assertThat
(
rootCause
.
getMessage
()).
isEqualTo
(
"Unable to find main class"
);
}
}
private
Throwable
getRootCause
(
Throwable
ex
)
{
Throwable
candidate
=
ex
;
while
(
candidate
.
getCause
()
!=
null
)
{
candidate
=
candidate
.
getCause
();
}
return
candidate
;
}
}
spring-boot-integration-tests/spring-boot-gradle-tests/src/test/resources/main-
in-boot-run
.gradle
→
spring-boot-integration-tests/spring-boot-gradle-tests/src/test/resources/main-
class
.gradle
View file @
fc463afb
...
...
@@ -14,10 +14,17 @@ apply plugin: 'spring-boot'
group
=
'installer'
version
=
'0.0.0'
bootRun
{
main
=
'org.springframework.boot.SpringApplication'
if
(
project
.
hasProperty
(
'bootRunMain'
))
{
bootRun
{
main
=
'org.springframework.boot.SpringApplication'
}
}
if
(
project
.
hasProperty
(
'nonJavaExecRun'
))
{
task
run
{
}
}
jar
{
baseName
=
'installer'
}
...
...
spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/run/FindMainClassTask.java
View file @
fc463afb
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
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.
...
...
@@ -24,6 +24,7 @@ import org.gradle.api.Task;
import
org.gradle.api.plugins.ApplicationPluginConvention
;
import
org.gradle.api.plugins.ExtraPropertiesExtension
;
import
org.gradle.api.tasks.Input
;
import
org.gradle.api.tasks.JavaExec
;
import
org.gradle.api.tasks.SourceSetOutput
;
import
org.gradle.api.tasks.TaskAction
;
...
...
@@ -85,9 +86,9 @@ public class FindMainClassTask extends DefaultTask {
mainClass
=
application
.
getMainClassName
();
}
Task
runTask
=
project
.
getTasks
().
findByName
(
"run"
);
JavaExec
runTask
=
findRunTask
(
project
);
if
(
mainClass
==
null
&&
runTask
!=
null
)
{
mainClass
=
(
String
)
runTask
.
property
(
"main"
);
mainClass
=
runTask
.
getMain
(
);
}
if
(
mainClass
==
null
)
{
...
...
@@ -122,9 +123,17 @@ public class FindMainClassTask extends DefaultTask {
application
.
setMainClassName
(
mainClass
);
}
if
(
runTask
!=
null
&&
!
runTask
.
hasProperty
(
"main"
))
{
runTask
.
set
Property
(
"main"
,
mainClass
);
runTask
.
set
Main
(
mainClass
);
}
return
mainClass
;
}
private
JavaExec
findRunTask
(
Project
project
)
{
Task
runTask
=
project
.
getTasks
().
findByName
(
"run"
);
if
(
runTask
instanceof
JavaExec
)
{
return
(
JavaExec
)
runTask
;
}
return
null
;
}
}
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