Skip to content

Commit d9ac95a

Browse files
committed
Gradle: make sure project compile configurations can be found instead of assuming they always exist
1 parent b5f99be commit d9ac95a

File tree

16 files changed

+437
-26
lines changed

16 files changed

+437
-26
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.quarkus.gradle;
2+
3+
import java.io.File;
4+
import java.nio.file.Path;
5+
6+
import org.gradle.testkit.runner.BuildResult;
7+
import org.gradle.testkit.runner.GradleRunner;
8+
import org.junit.jupiter.api.Test;
9+
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
12+
13+
public class BasicJavaPlatformModuleTest extends QuarkusGradleTestBase {
14+
15+
@Test
16+
public void testBasicPlatformModuleBuild() throws Exception {
17+
18+
final File projectDir = getProjectDir("basic-java-platform-module");
19+
20+
BuildResult build = GradleRunner.create()
21+
.forwardOutput()
22+
.withPluginClasspath()
23+
.withArguments(arguments(":application:quarkusBuild"))
24+
.withProjectDir(projectDir)
25+
.build();
26+
27+
Path p = projectDir.toPath().resolve("application").resolve("build").resolve("libs");
28+
assertThat(p).exists();
29+
assertThat(p.resolve("application-1.0.0-SNAPSHOT.jar")).exists();
30+
31+
p = projectDir.toPath().resolve("application").resolve("build").resolve("application-1.0.0-SNAPSHOT-runner.jar");
32+
assertThat(p).exists();
33+
}
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
plugins {
2+
id 'java'
3+
id 'io.quarkus'
4+
}
5+
6+
repositories {
7+
mavenLocal()
8+
mavenCentral()
9+
}
10+
11+
dependencies {
12+
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
13+
implementation 'io.quarkus:quarkus-resteasy'
14+
15+
implementation platform(project(':platform'))
16+
17+
testImplementation 'io.quarkus:quarkus-junit5'
18+
testImplementation 'io.rest-assured:rest-assured'
19+
}
20+
21+
compileJava {
22+
options.compilerArgs << '-parameters'
23+
}
24+
25+
java {
26+
sourceCompatibility = JavaVersion.VERSION_1_8
27+
targetCompatibility = JavaVersion.VERSION_1_8
28+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
####
2+
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
3+
#
4+
# Before building the docker image run:
5+
#
6+
# mvn package
7+
#
8+
# Then, build the image with:
9+
#
10+
# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/code-with-quarkus-jvm .
11+
#
12+
# Then run the container using:
13+
#
14+
# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus-jvm
15+
#
16+
###
17+
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.1
18+
19+
ARG JAVA_PACKAGE=java-1.8.0-openjdk-headless
20+
ARG RUN_JAVA_VERSION=1.3.5
21+
22+
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
23+
24+
# Install java and the run-java script
25+
# Also set up permissions for user `1001`
26+
RUN microdnf install openssl curl ca-certificates ${JAVA_PACKAGE} \
27+
&& microdnf update \
28+
&& microdnf clean all \
29+
&& mkdir /deployments \
30+
&& chown 1001 /deployments \
31+
&& chmod "g+rwX" /deployments \
32+
&& chown 1001:root /deployments \
33+
&& curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \
34+
&& chown 1001 /deployments/run-java.sh \
35+
&& chmod 540 /deployments/run-java.sh \
36+
&& echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security
37+
38+
# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size.
39+
ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
40+
41+
COPY build/lib/* /deployments/lib/
42+
COPY build/*-runner.jar /deployments/app.jar
43+
44+
EXPOSE 8080
45+
USER 1001
46+
47+
ENTRYPOINT [ "/deployments/run-java.sh" ]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
####
2+
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode
3+
#
4+
# Before building the docker image run:
5+
#
6+
# mvn package -Pnative -Dquarkus.native.container-build=true
7+
#
8+
# Then, build the image with:
9+
#
10+
# docker build -f src/main/docker/Dockerfile.native -t quarkus/code-with-quarkus .
11+
#
12+
# Then run the container using:
13+
#
14+
# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus
15+
#
16+
###
17+
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.1
18+
WORKDIR /work/
19+
COPY build/*-runner /work/application
20+
21+
# set up permissions for user `1001`
22+
RUN chmod 775 /work /work/application \
23+
&& chown -R 1001 /work \
24+
&& chmod -R "g+rwX" /work \
25+
&& chown -R 1001:root /work
26+
27+
EXPOSE 8080
28+
USER 1001
29+
30+
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.acme;
2+
3+
import javax.inject.Inject;
4+
import javax.ws.rs.GET;
5+
import javax.ws.rs.Path;
6+
import javax.ws.rs.Produces;
7+
import javax.ws.rs.core.MediaType;
8+
9+
@Path("/hello")
10+
public class ExampleResource {
11+
12+
@GET
13+
@Produces(MediaType.TEXT_PLAIN)
14+
public String hello() {
15+
return "hello";
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>code-with-quarkus - 1.0.0-SNAPSHOT</title>
6+
<style>
7+
h1, h2, h3, h4, h5, h6 {
8+
margin-bottom: 0.5rem;
9+
font-weight: 400;
10+
line-height: 1.5;
11+
}
12+
13+
h1 {
14+
font-size: 2.5rem;
15+
}
16+
17+
h2 {
18+
font-size: 2rem
19+
}
20+
21+
h3 {
22+
font-size: 1.75rem
23+
}
24+
25+
h4 {
26+
font-size: 1.5rem
27+
}
28+
29+
h5 {
30+
font-size: 1.25rem
31+
}
32+
33+
h6 {
34+
font-size: 1rem
35+
}
36+
37+
.lead {
38+
font-weight: 300;
39+
font-size: 2rem;
40+
}
41+
42+
.banner {
43+
font-size: 2.7rem;
44+
margin: 0;
45+
padding: 2rem 1rem;
46+
background-color: #00A1E2;
47+
color: white;
48+
}
49+
50+
body {
51+
margin: 0;
52+
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";
53+
}
54+
55+
code {
56+
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
57+
font-size: 87.5%;
58+
color: #e83e8c;
59+
word-break: break-word;
60+
}
61+
62+
.left-column {
63+
padding: .75rem;
64+
max-width: 75%;
65+
min-width: 55%;
66+
}
67+
68+
.right-column {
69+
padding: .75rem;
70+
max-width: 25%;
71+
}
72+
73+
.container {
74+
display: flex;
75+
width: 100%;
76+
}
77+
78+
li {
79+
margin: 0.75rem;
80+
}
81+
82+
.right-section {
83+
margin-left: 1rem;
84+
padding-left: 0.5rem;
85+
}
86+
87+
.right-section h3 {
88+
padding-top: 0;
89+
font-weight: 200;
90+
}
91+
92+
.right-section ul {
93+
border-left: 0.3rem solid #00A1E2;
94+
list-style-type: none;
95+
padding-left: 0;
96+
}
97+
98+
</style>
99+
</head>
100+
<body>
101+
102+
<div class="banner lead">
103+
Your new Cloud-Native application is ready!
104+
</div>
105+
106+
<div class="container">
107+
<div class="left-column">
108+
<p class="lead"> Congratulations, you have created a new Quarkus application.</p>
109+
110+
<h2>Why do you see this?</h2>
111+
112+
<p>This page is served by Quarkus. The source is in
113+
<code>src/main/resources/META-INF/resources/index.html</code>.</p>
114+
115+
<h2>What can I do from here?</h2>
116+
117+
<p>If not already done, run the application in <em>dev mode</em> using: <code>mvn compile quarkus:dev</code>.
118+
</p>
119+
<ul>
120+
<li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li>
121+
<li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li>
122+
<li>Configure your application in <code>src/main/resources/application.properties</code>.
123+
</li>
124+
</ul>
125+
126+
<h2>Do you like Quarkus?</h2>
127+
<p>Go give it a star on <a href="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/quarkusio/quarkus">GitHub</a>.</p>
128+
129+
<h2>How do I get rid of this page?</h2>
130+
<p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p>
131+
</div>
132+
<div class="right-column">
133+
<div class="right-section">
134+
<h3>Application</h3>
135+
<ul>
136+
<li>GroupId: org.acme</li>
137+
<li>ArtifactId: code-with-quarkus</li>
138+
<li>Version: 1.0.0-SNAPSHOT</li>
139+
<li>Quarkus Version: 1.2.1.Final</li>
140+
</ul>
141+
</div>
142+
<div class="right-section">
143+
<h3>Next steps</h3>
144+
<ul>
145+
<li><a href="https://quarkus.io/guides/maven-tooling.html" target="_blank">Setup your IDE</a></li>
146+
<li><a href="https://quarkus.io/guides/getting-started.html" target="_blank">Getting started</a></li>
147+
<li><a href="https://quarkus.io" target="_blank">Quarkus Web Site</a></li>
148+
</ul>
149+
</div>
150+
</div>
151+
</div>
152+
153+
154+
</body>
155+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Configuration file
2+
# key = value
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.acme;
2+
3+
import io.quarkus.test.junit.NativeImageTest;
4+
5+
@NativeImageTest
6+
public class NativeExampleResourceIT extends ExampleResourceTest {
7+
8+
// Execute the same tests but in native mode.
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.acme;
2+
3+
import io.quarkus.test.junit.QuarkusTest;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static io.restassured.RestAssured.given;
7+
import static org.hamcrest.CoreMatchers.is;
8+
9+
@QuarkusTest
10+
public class ExampleResourceTest {
11+
12+
@Test
13+
public void testHelloEndpoint() {
14+
given()
15+
.when().get("/hello")
16+
.then()
17+
.statusCode(200)
18+
.body(is("hello"));
19+
}
20+
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
buildscript {
2+
repositories {
3+
mavenLocal()
4+
mavenCentral()
5+
}
6+
}
7+
8+
allprojects {
9+
group 'org.acme'
10+
version '1.0.0-SNAPSHOT'
11+
}
12+
13+
subprojects{
14+
repositories {
15+
mavenLocal()
16+
mavenCentral()
17+
}
18+
}

0 commit comments

Comments
 (0)