Skip to content

Commit

Permalink
Add Maven Wrapper to generated projects
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Mar 15, 2019
1 parent c8feafa commit 97ea114
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 57 deletions.
3 changes: 3 additions & 0 deletions devtools/common/src/main/filtered/quarkus.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ plugin-artifactId=quarkus-maven-plugin
plugin-version=${project.version}

supported-maven-versions=${supported-maven-versions}
# the proposed version must be in the range of the supported versions
proposed-maven-version=3.5.4
maven-wrapper-version=0.7.4
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public static String getBomArtifactId() {
return get("bom-artifactId");
}

public static String getProposedMavenVersion() {
return get("proposed-maven-version");
}

public static String getMavenWrapperVersion() {
return get("maven-wrapper-version");
}

private static void loadProperties() {
URL url = MojoUtils.class.getClassLoader().getResource("quarkus.properties");
Objects.requireNonNull(url);
Expand Down
7 changes: 7 additions & 0 deletions devtools/maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@
<artifactId>jackson-databind</artifactId>
</dependency>

<!-- allows us to execute a mojo inside a mojo -->
<dependency>
<groupId>org.twdata.maven</groupId>
<artifactId>mojo-executor</artifactId>
<version>2.3.0</version>
</dependency>

<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
package io.quarkus.maven;

import static org.fusesource.jansi.Ansi.ansi;
import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
import static org.twdata.maven.mojoexecutor.MojoExecutor.element;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
import static org.twdata.maven.mojoexecutor.MojoExecutor.goal;
import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.name;
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;

import java.io.File;
import java.io.IOException;
Expand All @@ -29,6 +39,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -83,6 +94,9 @@ public class CreateProjectMojo extends AbstractMojo {
@Component
private MavenVersionEnforcer mavenVersionEnforcer;

@Component
private BuildPluginManager pluginManager;

@Override
public void execute() throws MojoExecutionException {
// We detect the Maven version during the project generation to indicate the user immediately that the installed
Expand Down Expand Up @@ -136,6 +150,8 @@ public void execute() throws MojoExecutionException {
new AddExtensions(new File(projectRoot, "pom.xml"))
.addExtensions(extensions);
}

createMavenWrapper();
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
Expand All @@ -144,6 +160,26 @@ public void execute() throws MojoExecutionException {
}
}

private void createMavenWrapper() {
try {
executeMojo(
plugin(
groupId("io.takari"),
artifactId("maven"),
version(MojoUtils.getMavenWrapperVersion())),
goal("wrapper"),
configuration(
element(name("maven"), MojoUtils.getProposedMavenVersion())),
executionEnvironment(
project,
session,
pluginManager));
} catch (Exception e) {
// no reason to fail if the wrapper could not be created
getLog().debug("Unable to create Maven Wrapper");
}
}

private SourceType determineSourceType(Set<String> extensions) {
return extensions.stream().anyMatch(e -> e.toLowerCase().contains("kotlin"))
? SourceType.KOTLIN
Expand Down
8 changes: 4 additions & 4 deletions docs/src/main/asciidoc/application-configuration-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ public class GreetingResourceTest {

== Package and run the application

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

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

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

== Overriding properties at runtime

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

[source,shell]
--
mvn clean package
./mvnw clean package
--

Extensions do define _some_ properties as overridable at runtime.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ NOTE: The methods can access injected beans. Check the {quickstarts-blob-url}/ap

== Package and run the application

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

As usual, the application can be packaged using `mvn clean package` and executed using the `-runner.jar` file.
You can also generate the native executable using `mvn clean package -Pnative`.
As usual, the application can be packaged using `./mvnw clean package` and executed using the `-runner.jar` file.
You can also generate the native executable using `./mvnw clean package -Pnative`.
8 changes: 4 additions & 4 deletions docs/src/main/asciidoc/building-native-image-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ If you have generated the application from the previous tutorial, you can find i

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

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

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

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

[source,shell]
----
mvn package -Pnative -Dnative-image.docker-build=true
./mvnw package -Pnative -Dnative-image.docker-build=true
----

The produced executable will be a 64 bit Linux executable, so depending on your operating system it may no longer be runnable.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/extension-authors-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -565,5 +565,5 @@ memory in a runtime class loader. To have these classes written out to disk for

[source,shell]
----
mvn clean install -Dquarkus.debug.generated-classes-dir=./target/app-generated-classes
./mvnw clean install -Dquarkus.debug.generated-classes-dir=./target/app-generated-classes
----
4 changes: 2 additions & 2 deletions docs/src/main/asciidoc/fault-tolerance-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Why not check that our application works? Run the Quarkus development server wit

[source,shell]
----
mvn compile quarkus:dev
./mvnw compile quarkus:dev
----

and open `http://localhost:8080/coffee` in your browser. Make couple of requests (remember, some of them we expect
Expand Down Expand Up @@ -461,7 +461,7 @@ All that is needed to enable the fault tolerance features in Quarkus is:
+
[source,shell]
----
mvn quarkus:add-extension -Dextensions="smallrye-fault-tolerance"
./mvnw quarkus:add-extension -Dextensions="smallrye-fault-tolerance"
----
* or simply adding the following Maven dependency:
+
Expand Down
8 changes: 4 additions & 4 deletions docs/src/main/asciidoc/getting-started-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ of the resource is created and not one per request. You can configure this using
== Running the application

Now we are ready to run our application.
Use: `mvn compile quarkus:dev`:
Use: `./mvnw compile quarkus:dev`:

[source,shell]
----
Expand Down Expand Up @@ -250,7 +250,7 @@ public class GreetingResource {
}
----

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

== Development Mode
Expand Down Expand Up @@ -352,7 +352,7 @@ public class GreetingResourceTest {

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

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

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

== Packaging and run the application

The application is packaged using `mvn package`.
The application is packaged using `./mvnw package`.
It produces 2 jar files:

* `getting-started-1.0-SNAPSHOT.jar` - containing just the classes and resources of the projects, it's the regular
Expand Down
10 changes: 5 additions & 5 deletions docs/src/main/asciidoc/jwt-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ Now we are ready to run our application. Use:

[source,shell]
----
mvn compile quarkus:dev
./mvnw compile quarkus:dev
----

and you should see output similar to:

.quarkus:dev Output
[source,shell]
----
$ mvn compile quarkus:dev
$ ./mvnw compile quarkus:dev
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< org.acme:using-jwt-rbac >-----------------------
Expand Down Expand Up @@ -238,7 +238,7 @@ public class TokenSecuredResource {
<2> @RolesAllowed is a JSR 250 common security annotation that indicates that the given endpoint is accessible by a caller if
they have either a "Echoer" or "Subscriber" role assigned.

After you make this addition to your `TokenSecuredResource`, rerun the `mvn compile quarkus:dev` command, and then try `curl -v http://127.0.0.1:8080/secured/roles-allowed; echo` to attempt to access the new endpoint. Your output should be:
After you make this addition to your `TokenSecuredResource`, rerun the `./mvnw compile quarkus:dev` command, and then try `curl -v http://127.0.0.1:8080/secured/roles-allowed; echo` to attempt to access the new endpoint. Your output should be:

.curl command for /secured/roles-allowed
[source,shell]
Expand Down Expand Up @@ -676,7 +676,7 @@ Now we can generate a JWT to use with `TokenSecuredResource` endpoint. To do thi
mvn exec:java -Dexec.mainClass=org.acme.jwt.GenerateToken -Dexec.classpathScope=test
----

TIP: You may need to run `mvn test-compile` before this if you are working strictly from the command line and not an IDE that
TIP: You may need to run `./mvnw test-compile` before this if you are working strictly from the command line and not an IDE that
automatically compiles code as you write it.

.Sample JWT Generation Output
Expand Down Expand Up @@ -758,7 +758,7 @@ eyJraWQiOiJcL3ByaXZhdGVLZXkucGVtIiwidHlwIjoiSldUIiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiO


== Finally, Secured Access to /secured/roles-allowed
Now let's use this to make a secured request to the /secured/roles-allowed endpoint. Make sure you have the {project-name} server running using the `mvn compile quarkus:dev` command, and then run the following command, making sure to use your version of the generated JWT from the previous step:
Now let's use this to make a secured request to the /secured/roles-allowed endpoint. Make sure you have the {project-name} server running using the `./mvnw compile quarkus:dev` command, and then run the following command, making sure to use your version of the generated JWT from the previous step:

[source,shell]
----
Expand Down
4 changes: 2 additions & 2 deletions docs/src/main/asciidoc/kotlin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Future versions of {project-name} will configure the Kotlin compiler plugin in a
{project-name} provides support for live reloading changes made to source code. This support is also available to Kotlin, meaning that developers can update their Kotlin source
code and immediately see their changes reflected.

To see this feature in action, first execute: `mvn compile quarkus:dev`
To see this feature in action, first execute: `./mvnw compile quarkus:dev`

When executing an HTTP GET request against `http://localhost:8080/greeting`, you should get `hello` as a response.

Expand All @@ -138,4 +138,4 @@ One thing to note is that the live reload feature is not available when making c

== Packaging the application

As usual, the application can be packaged using `mvn clean package` and executed using the `-runner.jar` file. You can also build the native executable using `mvn package -Pnative`.
As usual, the application can be packaged using `./mvnw clean package` and executed using the `-runner.jar` file. You can also build the native executable using `./mvnw package -Pnative`.
20 changes: 10 additions & 10 deletions docs/src/main/asciidoc/maven-tooling.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ Instructions to build the image and run the container are written in the `Docker
From inside a {project-name} project, you can obtain a list of the available extensions with:

[source,shell]
mvn quarkus:list-extensions
./mvnw quarkus:list-extensions

You can enable an extension using:

[source,shell]
mvn quarkus:add-extension -Dextensions="hibernate-validator"
./mvnw quarkus:add-extension -Dextensions="hibernate-validator"

Extensions are passed using a comma-separated list.

Expand All @@ -81,7 +81,7 @@ Extensions are passed using a comma-separated list.
Run your application with:

[source,shell]
mvn compile quarkus:dev
./mvnw compile quarkus:dev

You can then update the application sources, resources and configurations.
The changes are automatically reflected in your running application.
Expand All @@ -102,7 +102,7 @@ Hit `CTRL+C` to stop the application.
You can run a {project-name} application in debug mode using:

[source,shell]
mvn compile quarkus:dev -Ddebug=true
./mvnw compile quarkus:dev -Ddebug=true

Then, attach your debugger to `localhost:5005`.

Expand All @@ -118,7 +118,7 @@ In the wizard, select: `Maven -> Existing Maven Project`.
On the next screen, select the root location of the project.
The next screen list the found modules; select the generated project and click on `Finish`. Done!

In a separated terminal, run `mvn compile quarkus:dev`, and enjoy a highly productive environment.
In a separated terminal, run `./mvnw compile quarkus:dev`, and enjoy a highly productive environment.

**IntelliJ**

Expand All @@ -130,7 +130,7 @@ In IntelliJ:
4. Next a few times (review the different options if needed)
5. On the last screen click on Finish

In a separated terminal or in the embedded terminal, run `mvn compile quarkus:dev`. Enjoy!
In a separated terminal or in the embedded terminal, run `./mvnw compile quarkus:dev`. Enjoy!

**Apache Netbeans**

Expand All @@ -140,7 +140,7 @@ In Netbeans:
2. Select the project root
3. Click on `Open Project`

In a separated terminal or the embedded terminal, go to the project root and run `mvn compile quarkus:dev`. Enjoy!
In a separated terminal or the embedded terminal, go to the project root and run `./mvnw compile quarkus:dev`. Enjoy!

**Visual Studio Code**

Expand All @@ -153,14 +153,14 @@ Native executables make {project-name} applications ideal for containers and ser
Make sure to have `GRAALVM_HOME` configured and pointing to GraalVM version {graalvm-version}.
Verify that your `pom.xml` has the proper `native` profile (see <<build-tool-maven>>).

Create a native executable using: `mvn package -Pnative`.
Create a native executable using: `./mvnw package -Pnative`.
A native executable will be present in `target/`.

To run Integration Tests on the native executable, make sure to have the proper Maven plugin configured (see <<build-tool-maven>>) and launch the `verify` goal.

[source,shell]
----
mvn verify -Pnative
./mvnw verify -Pnative
...
[quarkus-quickstart-runner:50955] universe: 391.96 ms
[quarkus-quickstart-runner:50955] (parse): 904.37 ms
Expand Down Expand Up @@ -196,7 +196,7 @@ To create an executable that will run in a container, use the following:

[source,shell]
----
mvn package -Pnative -Dnative-image.docker-build=true
./mvnw package -Pnative -Dnative-image.docker-build=true
----

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

0 comments on commit 97ea114

Please sign in to comment.