Skip to content

Commit 97ea114

Browse files
committed
Add Maven Wrapper to generated projects
Fixes: #1498
1 parent c8feafa commit 97ea114

21 files changed

+111
-57
lines changed

devtools/common/src/main/filtered/quarkus.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ plugin-artifactId=quarkus-maven-plugin
2929
plugin-version=${project.version}
3030

3131
supported-maven-versions=${supported-maven-versions}
32+
# the proposed version must be in the range of the supported versions
33+
proposed-maven-version=3.5.4
34+
maven-wrapper-version=0.7.4

devtools/common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ public static String getBomArtifactId() {
8484
return get("bom-artifactId");
8585
}
8686

87+
public static String getProposedMavenVersion() {
88+
return get("proposed-maven-version");
89+
}
90+
91+
public static String getMavenWrapperVersion() {
92+
return get("maven-wrapper-version");
93+
}
94+
8795
private static void loadProperties() {
8896
URL url = MojoUtils.class.getClassLoader().getResource("quarkus.properties");
8997
Objects.requireNonNull(url);

devtools/maven/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@
114114
<artifactId>jackson-databind</artifactId>
115115
</dependency>
116116

117+
<!-- allows us to execute a mojo inside a mojo -->
118+
<dependency>
119+
<groupId>org.twdata.maven</groupId>
120+
<artifactId>mojo-executor</artifactId>
121+
<version>2.3.0</version>
122+
</dependency>
123+
117124
<!-- test -->
118125
<dependency>
119126
<groupId>org.junit.jupiter</groupId>

devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
package io.quarkus.maven;
1919

2020
import static org.fusesource.jansi.Ansi.ansi;
21+
import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
22+
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
23+
import static org.twdata.maven.mojoexecutor.MojoExecutor.element;
24+
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
25+
import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
26+
import static org.twdata.maven.mojoexecutor.MojoExecutor.goal;
27+
import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId;
28+
import static org.twdata.maven.mojoexecutor.MojoExecutor.name;
29+
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
30+
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;
2131

2232
import java.io.File;
2333
import java.io.IOException;
@@ -29,6 +39,7 @@
2939
import org.apache.commons.lang3.StringUtils;
3040
import org.apache.maven.execution.MavenSession;
3141
import org.apache.maven.plugin.AbstractMojo;
42+
import org.apache.maven.plugin.BuildPluginManager;
3243
import org.apache.maven.plugin.MojoExecutionException;
3344
import org.apache.maven.plugins.annotations.Component;
3445
import org.apache.maven.plugins.annotations.Mojo;
@@ -83,6 +94,9 @@ public class CreateProjectMojo extends AbstractMojo {
8394
@Component
8495
private MavenVersionEnforcer mavenVersionEnforcer;
8596

97+
@Component
98+
private BuildPluginManager pluginManager;
99+
86100
@Override
87101
public void execute() throws MojoExecutionException {
88102
// We detect the Maven version during the project generation to indicate the user immediately that the installed
@@ -136,6 +150,8 @@ public void execute() throws MojoExecutionException {
136150
new AddExtensions(new File(projectRoot, "pom.xml"))
137151
.addExtensions(extensions);
138152
}
153+
154+
createMavenWrapper();
139155
} catch (IOException e) {
140156
throw new MojoExecutionException(e.getMessage(), e);
141157
}
@@ -144,6 +160,26 @@ public void execute() throws MojoExecutionException {
144160
}
145161
}
146162

163+
private void createMavenWrapper() {
164+
try {
165+
executeMojo(
166+
plugin(
167+
groupId("io.takari"),
168+
artifactId("maven"),
169+
version(MojoUtils.getMavenWrapperVersion())),
170+
goal("wrapper"),
171+
configuration(
172+
element(name("maven"), MojoUtils.getProposedMavenVersion())),
173+
executionEnvironment(
174+
project,
175+
session,
176+
pluginManager));
177+
} catch (Exception e) {
178+
// no reason to fail if the wrapper could not be created
179+
getLog().debug("Unable to create Maven Wrapper");
180+
}
181+
}
182+
147183
private SourceType determineSourceType(Set<String> extensions) {
148184
return extensions.stream().anyMatch(e -> e.toLowerCase().contains("kotlin"))
149185
? SourceType.KOTLIN

docs/src/main/asciidoc/application-configuration-guide.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ public class GreetingResourceTest {
148148

149149
== Package and run the application
150150

151-
Run the application with: `mvn compile quarkus:dev`.
151+
Run the application with: `./mvnw compile quarkus:dev`.
152152
Open your browser to http://localhost:8080/greeting.
153153

154154
Changing the configuration file is immediately reflected.
155155
You can add the `greeting.suffix`, remove the other properties, change the values, etc.
156156

157-
As usual, the application can be packaged using `mvn clean package` and executed using the `-runner.jar` file.
158-
You can also generate the native executable with `mvn clean package -Pnative`.
157+
As usual, the application can be packaged using `./mvnw clean package` and executed using the `-runner.jar` file.
158+
You can also generate the native executable with `./mvnw clean package -Pnative`.
159159

160160
== Overriding properties at runtime
161161

@@ -165,7 +165,7 @@ To change them, make sure to repackage your application.
165165

166166
[source,shell]
167167
--
168-
mvn clean package
168+
./mvnw clean package
169169
--
170170

171171
Extensions do define _some_ properties as overridable at runtime.

docs/src/main/asciidoc/application-lifecycle-events-guide.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ NOTE: The methods can access injected beans. Check the {quickstarts-blob-url}/ap
9090

9191
== Package and run the application
9292

93-
Run the application with: `mvn compile quarkus:dev`, the logged message is printed.
93+
Run the application with: `./mvnw compile quarkus:dev`, the logged message is printed.
9494
When the application is stopped, the second log message is printed.
9595

96-
As usual, the application can be packaged using `mvn clean package` and executed using the `-runner.jar` file.
97-
You can also generate the native executable using `mvn clean package -Pnative`.
96+
As usual, the application can be packaged using `./mvnw clean package` and executed using the `-runner.jar` file.
97+
You can also generate the native executable using `./mvnw clean package -Pnative`.

docs/src/main/asciidoc/building-native-image-guide.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ If you have generated the application from the previous tutorial, you can find i
8787

8888
We use a profile because, you will see very soon, packaging the native executable takes a _few_ seconds.
8989

90-
Create a native executable using: `mvn package -Pnative`.
90+
Create a native executable using: `./mvnw package -Pnative`.
9191

9292
In addition to the regular files, the build also produces `target/quarkus-quickstart-runner`.
9393
You can run it using: `./target/quarkus-quickstart-runner`.
@@ -142,10 +142,10 @@ public class NativeGreetingResourceIT extends GreetingResourceTest { // <2>
142142
The executable is retrieved using the `native.image.path` system property configured in the _Failsafe Maven Plugin_.
143143
<2> We extend our previous tests, but you can also implement your tests
144144

145-
To see the `NativeGreetingResourceIT` run against the native executable, runs `mvn verify -Pnative`:
145+
To see the `NativeGreetingResourceIT` run against the native executable, runs `./mvnw verify -Pnative`:
146146
[source,shell]
147147
----
148-
mvn verify -Pnative
148+
./mvnw verify -Pnative
149149
...
150150
[quarkus-quickstart-runner:50955] universe: 391.96 ms
151151
[quarkus-quickstart-runner:50955] (parse): 904.37 ms
@@ -189,7 +189,7 @@ we will instruct the Maven build to produce an executable from inside a Docker c
189189

190190
[source,shell]
191191
----
192-
mvn package -Pnative -Dnative-image.docker-build=true
192+
./mvnw package -Pnative -Dnative-image.docker-build=true
193193
----
194194

195195
The produced executable will be a 64 bit Linux executable, so depending on your operating system it may no longer be runnable.

docs/src/main/asciidoc/extension-authors-guide.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,5 +565,5 @@ memory in a runtime class loader. To have these classes written out to disk for
565565

566566
[source,shell]
567567
----
568-
mvn clean install -Dquarkus.debug.generated-classes-dir=./target/app-generated-classes
568+
./mvnw clean install -Dquarkus.debug.generated-classes-dir=./target/app-generated-classes
569569
----

docs/src/main/asciidoc/fault-tolerance-guide.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Why not check that our application works? Run the Quarkus development server wit
209209

210210
[source,shell]
211211
----
212-
mvn compile quarkus:dev
212+
./mvnw compile quarkus:dev
213213
----
214214

215215
and open `http://localhost:8080/coffee` in your browser. Make couple of requests (remember, some of them we expect
@@ -461,7 +461,7 @@ All that is needed to enable the fault tolerance features in Quarkus is:
461461
+
462462
[source,shell]
463463
----
464-
mvn quarkus:add-extension -Dextensions="smallrye-fault-tolerance"
464+
./mvnw quarkus:add-extension -Dextensions="smallrye-fault-tolerance"
465465
----
466466
* or simply adding the following Maven dependency:
467467
+

docs/src/main/asciidoc/getting-started-guide.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ of the resource is created and not one per request. You can configure this using
162162
== Running the application
163163

164164
Now we are ready to run our application.
165-
Use: `mvn compile quarkus:dev`:
165+
Use: `./mvnw compile quarkus:dev`:
166166

167167
[source,shell]
168168
----
@@ -250,7 +250,7 @@ public class GreetingResource {
250250
}
251251
----
252252

253-
If you stopped the application, restart the application with `mvn compile quarkus:dev`.
253+
If you stopped the application, restart the application with `./mvnw compile quarkus:dev`.
254254
Then check that http://localhost:8080/hello/greeting/quarkus returns `hello quarkus`.
255255

256256
== Development Mode
@@ -352,7 +352,7 @@ public class GreetingResourceTest {
352352

353353
These tests use http://rest-assured.io/[RestAssured], but feel free to use your favorite library.
354354

355-
You can run the test from your IDE directly (be sure you stopped the application first), or from Maven using: `mvn test`.
355+
You can run the test from your IDE directly (be sure you stopped the application first), or from Maven using: `./mvnw test`.
356356

357357
By default tests will run on port `8081` so as not to conflict with the running application. We automatically
358358
configure RestAssured to use this port. If you want to use a different client you should use the `@TestHTTPResource`
@@ -373,7 +373,7 @@ property called `test.url` that is set to the base test URL for situations where
373373

374374
== Packaging and run the application
375375

376-
The application is packaged using `mvn package`.
376+
The application is packaged using `./mvnw package`.
377377
It produces 2 jar files:
378378

379379
* `getting-started-1.0-SNAPSHOT.jar` - containing just the classes and resources of the projects, it's the regular

0 commit comments

Comments
 (0)