-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7441 from aloubyansky/gradle-build-jar-deps
Gradle: prefer local deps as JARs when building runnable JARs
- Loading branch information
Showing
18 changed files
with
464 additions
and
40 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
devtools/gradle/src/functionalTest/java/io/quarkus/gradle/BasicMultiModuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.quarkus.gradle; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
|
||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.GradleRunner; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
|
||
public class BasicMultiModuleTest extends QuarkusGradleTestBase { | ||
|
||
@Test | ||
public void testBasicMultiModuleBuild() throws Exception { | ||
|
||
final File projectDir = getProjectDir("basic-multi-module-project"); | ||
|
||
BuildResult build = GradleRunner.create() | ||
.forwardOutput() | ||
.withPluginClasspath() | ||
.withArguments(arguments(":application:quarkusBuild")) | ||
.withProjectDir(projectDir) | ||
.build(); | ||
|
||
final Path commonLibs = projectDir.toPath().resolve("common").resolve("build").resolve("libs"); | ||
assertThat(commonLibs).exists(); | ||
assertThat(commonLibs.resolve("common.jar")).exists(); | ||
|
||
final Path applicationLib = projectDir.toPath().resolve("application").resolve("build").resolve("lib"); | ||
assertThat(applicationLib).exists(); | ||
assertThat(applicationLib.resolve("quarkus-basic-multi-module-build.common.jar")).exists(); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
devtools/gradle/src/functionalTest/java/io/quarkus/gradle/QuarkusGradleTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.quarkus.gradle; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
public class QuarkusGradleTestBase { | ||
|
||
protected File getProjectDir(final String projectName) throws URISyntaxException, IOException, FileNotFoundException { | ||
final URL projectUrl = Thread.currentThread().getContextClassLoader().getResource(projectName); | ||
if(projectUrl == null) { | ||
throw new IllegalStateException("Failed to locate test project " + projectName); | ||
} | ||
final File projectDir = new File(projectUrl.toURI()); | ||
if(!projectDir.isDirectory()) { | ||
throw new IllegalStateException(projectDir + " is not a directory"); | ||
} | ||
|
||
final File projectProps = new File(projectDir, "gradle.properties"); | ||
if(!projectProps.exists()) { | ||
throw new IllegalStateException("Failed to locate " + projectProps); | ||
} | ||
final Properties props = new Properties(); | ||
try(InputStream is = new FileInputStream(projectProps)) { | ||
props.load(is); | ||
} | ||
final String quarkusVersion = getQuarkusVersion(); | ||
props.setProperty("quarkusPlatformVersion", quarkusVersion); | ||
props.setProperty("quarkusPluginVersion", quarkusVersion); | ||
try(OutputStream os = new FileOutputStream(projectProps)) { | ||
props.store(os, "Quarkus Gradle TS"); | ||
} | ||
return projectDir; | ||
} | ||
|
||
protected String getQuarkusVersion() throws IOException { | ||
final Path curDir = Paths.get("").toAbsolutePath().normalize(); | ||
final Path gradlePropsFile = curDir.resolve("gradle.properties"); | ||
Properties props = new Properties(); | ||
try(InputStream is = Files.newInputStream(gradlePropsFile)) { | ||
props.load(is); | ||
} | ||
final String quarkusVersion = props.getProperty("version"); | ||
if(quarkusVersion == null) { | ||
throw new IllegalStateException("Failed to locate Quarkus version in " + gradlePropsFile); | ||
} | ||
return quarkusVersion; | ||
} | ||
|
||
protected List<String> arguments(String... argument) { | ||
List<String> arguments = new ArrayList<>(); | ||
arguments.addAll(Arrays.asList(argument)); | ||
String mavenRepoLocal = System.getProperty("maven.repo.local", System.getenv("MAVEN_LOCAL_REPO")); | ||
if (mavenRepoLocal != null) { | ||
arguments.add("-Dmaven.repo.local=" + mavenRepoLocal); | ||
} | ||
return arguments; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...s/gradle/src/functionalTest/resources/basic-multi-module-project/application/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
id 'io.quarkus' | ||
} | ||
|
||
dependencies { | ||
implementation project(":common") | ||
} |
22 changes: 22 additions & 0 deletions
22
...multi-module-project/application/src/main/java/org/acme/quarkus/sample/HelloResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.acme.quarkus.sample; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.acme.common.CommonBean; | ||
|
||
@Path("/hello") | ||
public class HelloResource { | ||
|
||
@Inject | ||
CommonBean common; | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
return "hello " + common.getName(); | ||
} | ||
} |
152 changes: 152 additions & 0 deletions
152
...s/basic-multi-module-project/application/src/main/resources/META-INF/resources/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>my-quarkus-project - 1.0-SNAPSHOT</title> | ||
<style> | ||
h1, h2, h3, h4, h5, h6 { | ||
margin-bottom: 0.5rem; | ||
font-weight: 400; | ||
line-height: 1.5; | ||
} | ||
|
||
h1 { | ||
font-size: 2.5rem; | ||
} | ||
|
||
h2 { | ||
font-size: 2rem | ||
} | ||
|
||
h3 { | ||
font-size: 1.75rem | ||
} | ||
|
||
h4 { | ||
font-size: 1.5rem | ||
} | ||
|
||
h5 { | ||
font-size: 1.25rem | ||
} | ||
|
||
h6 { | ||
font-size: 1rem | ||
} | ||
|
||
.lead { | ||
font-weight: 300; | ||
font-size: 2rem; | ||
} | ||
|
||
.banner { | ||
font-size: 2.7rem; | ||
margin: 0; | ||
padding: 2rem 1rem; | ||
background-color: #00A1E2; | ||
color: white; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; | ||
} | ||
|
||
code { | ||
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; | ||
font-size: 87.5%; | ||
color: #e83e8c; | ||
word-break: break-word; | ||
} | ||
|
||
.left-column { | ||
padding: .75rem; | ||
max-width: 75%; | ||
min-width: 55%; | ||
} | ||
|
||
.right-column { | ||
padding: .75rem; | ||
max-width: 25%; | ||
} | ||
|
||
.container { | ||
display: flex; | ||
width: 100%; | ||
} | ||
|
||
li { | ||
margin: 0.75rem; | ||
} | ||
|
||
.right-section { | ||
margin-left: 1rem; | ||
padding-left: 0.5rem; | ||
} | ||
|
||
.right-section h3 { | ||
padding-top: 0; | ||
font-weight: 200; | ||
} | ||
|
||
.right-section ul { | ||
border-left: 0.3rem solid #00A1E2; | ||
list-style-type: none; | ||
padding-left: 0; | ||
} | ||
|
||
</style> | ||
</head> | ||
<body> | ||
|
||
<div class="banner lead"> | ||
Your new Cloud-Native application is ready! | ||
</div> | ||
|
||
<div class="container"> | ||
<div class="left-column"> | ||
<p class="lead"> Congratulations, you have created a new Quarkus application.</p> | ||
|
||
<h2>Why do you see this?</h2> | ||
|
||
<p>This page is served by Quarkus. The source is in | ||
<code>src/main/resources/META-INF/resources/index.html</code>.</p> | ||
|
||
<h2>What can I do from here?</h2> | ||
|
||
<p>If not already done, run the application in <em>dev mode</em> using: <code>mvn compile quarkus:dev</code>. | ||
</p> | ||
<ul> | ||
<li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li> | ||
<li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li> | ||
<li>Configure your application in <code>src/main/resources/application.properties</code>. | ||
</li> | ||
</ul> | ||
|
||
<h2>How do I get rid of this page?</h2> | ||
<p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p> | ||
</div> | ||
<div class="right-column"> | ||
<div class="right-section"> | ||
<h3>Application</h3> | ||
<ul> | ||
<li>GroupId: org.acme.quarkus.sample</li> | ||
<li>ArtifactId: my-quarkus-project</li> | ||
<li>Version: 1.0-SNAPSHOT</li> | ||
<li>Quarkus Version: 999-SNAPSHOT</li> | ||
</ul> | ||
</div> | ||
<div class="right-section"> | ||
<h3>Next steps</h3> | ||
<ul> | ||
<li><a href="https://quarkus.io/guides/maven-tooling.html" target="_blank">Setup your IDE</a></li> | ||
<li><a href="https://quarkus.io/guides/getting-started.html" target="_blank">Getting started</a></li> | ||
<li><a href="https://quarkus.io" target="_blank">Quarkus Web Site</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
</body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
...esources/basic-multi-module-project/application/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Configuration file | ||
# key = value |
50 changes: 50 additions & 0 deletions
50
devtools/gradle/src/functionalTest/resources/basic-multi-module-project/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
buildscript { | ||
|
||
repositories { | ||
jcenter() | ||
mavenLocal() | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
|
||
} | ||
|
||
apply plugin: 'java' | ||
|
||
group = 'com.quarkus.demo' | ||
version = '1.0' | ||
|
||
|
||
subprojects { | ||
|
||
apply plugin: 'java' | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
test { | ||
dependsOn 'cleanTest' | ||
dependsOn 'quarkusTestConfig' | ||
useJUnitPlatform() | ||
forkEvery 1 | ||
} | ||
|
||
repositories { | ||
jcenter() | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'io.quarkus:quarkus-resteasy' | ||
|
||
testImplementation 'io.quarkus:quarkus-junit5' | ||
testImplementation 'io.rest-assured:rest-assured' | ||
|
||
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") | ||
|
||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
devtools/gradle/src/functionalTest/resources/basic-multi-module-project/common/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
id 'io.quarkus' | ||
id 'java-library' | ||
} | ||
|
||
dependencies { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...resources/basic-multi-module-project/common/src/main/java/org/acme/common/CommonBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.acme.common; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
|
||
@RequestScoped | ||
public class CommonBean { | ||
|
||
public String getName() { | ||
return "common"; | ||
} | ||
} |
Oops, something went wrong.