Repository: quarkusio/quarkus
Issue: Quarkus CLI test are run even if `--no-tests` is specified

## Describe the bug
When building using the CLI with command `quarkus build --no-tests`  the tests are still executed.

### Expected behavior
No tests should be run

### Actual behavior
Tests are run 


## To Reproduce

Link to a small reproducer (preferably a Maven project if the issue is not Gradle-specific).

Or attach an archive containing the reproducer to the issue.

Steps to reproduce the behavior:
1.  `quarkus create app -a bug-reproducer` 
2.  `cd bug-reproducer`
3.  `quarkus build --no-tests`

### Configuration


### Screenshots
(If applicable, add screenshots to help explain your problem.)

## Environment (please complete the following information):

### Output of `uname -a` or `ver`
Darwin tqvarnst-mac 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64

### Output of `java -version`
openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-16.0.1+9 (build 16.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-16.0.1+9 (build 16.0.1+9, mixed mode, sharing)

### GraalVM version (if different from Java)

### Quarkus version or git rev
2.0.0.Final

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)
Quarkus CLI
```
> quarkus --version
Client Version 2.0.0.Final
```

## Additional context
(Add any other context about the problem here.)


Changed files:
devtools/cli/src/main/java/io/quarkus/cli/Build.java, devtools/cli/src/main/java/io/quarkus/cli/build/JBangRunner.java, devtools/cli/src/test/java/io/quarkus/cli/CliNonProjectTest.java, devtools/cli/src/test/java/io/quarkus/cli/CliProjectMavenTest.java, devtools/cli/src/test/java/io/quarkus/cli/CliProjectJBangTest.java, devtools/cli/src/main/java/io/quarkus/cli/common/BuildOptions.java, devtools/cli/src/test/java/io/quarkus/cli/CliDriver.java, devtools/cli/src/test/java/io/quarkus/cli/CliProjectGradleTest.java

diff --git a/devtools/cli/src/main/java/io/quarkus/cli/Build.java b/devtools/cli/src/main/java/io/quarkus/cli/Build.java
index 15968b8d693..bb0f29dbaa1 100644
--- a/devtools/cli/src/main/java/io/quarkus/cli/Build.java
+++ b/devtools/cli/src/main/java/io/quarkus/cli/Build.java
@@ -64,10 +64,7 @@ void dryRunBuild(CommandLine.Help help, BuildTool buildTool, BuildSystemRunner.B
 
     @Override
     public String toString() {
-        return "Build [clean=" + buildOptions.clean
-                + ", buildNative=" + buildOptions.buildNative
-                + ", offline=" + buildOptions.offline
-                + ", runTests=" + buildOptions.runTests
+        return "Build [buildOptions=" + buildOptions
                 + ", properties=" + propertiesOptions.properties
                 + ", output=" + output
                 + ", params=" + params + "]";
diff --git a/devtools/cli/src/main/java/io/quarkus/cli/build/JBangRunner.java b/devtools/cli/src/main/java/io/quarkus/cli/build/JBangRunner.java
index 8fea16b1df3..592b3483818 100644
--- a/devtools/cli/src/main/java/io/quarkus/cli/build/JBangRunner.java
+++ b/devtools/cli/src/main/java/io/quarkus/cli/build/JBangRunner.java
@@ -82,7 +82,12 @@ public BuildCommandArgs prepareBuild(BuildOptions buildOptions, RunModeOption ru
         if (buildOptions.buildNative) {
             args.add("--native");
         }
+        if (buildOptions.clean) {
+            args.add("--fresh");
+        }
+
         args.add("build");
+        args.addAll(flattenMappedProperties(propertiesOptions.properties));
         args.addAll(params);
         args.add(getMainPath());
         return prependExecutable(args);
diff --git a/devtools/cli/src/main/java/io/quarkus/cli/common/BuildOptions.java b/devtools/cli/src/main/java/io/quarkus/cli/common/BuildOptions.java
index 7aa0807587b..c67fd0598d6 100644
--- a/devtools/cli/src/main/java/io/quarkus/cli/common/BuildOptions.java
+++ b/devtools/cli/src/main/java/io/quarkus/cli/common/BuildOptions.java
@@ -13,10 +13,17 @@ public class BuildOptions {
     @CommandLine.Option(order = 5, names = { "--offline" }, description = "Work offline.", defaultValue = "false")
     public boolean offline = false;
 
-    @CommandLine.Option(order = 6, names = { "--tests" }, description = "Run tests.", negatable = true)
-    public boolean runTests = true;
+    @CommandLine.Option(order = 6, names = {
+            "--no-tests" }, description = "Run tests.", negatable = true, defaultValue = "false")
+    public boolean skipTests = false;
 
     public boolean skipTests() {
-        return !runTests;
+        return skipTests;
+    }
+
+    @Override
+    public String toString() {
+        return "BuildOptions [buildNative=" + buildNative + ", clean=" + clean + ", offline=" + offline + ", skipTests="
+                + skipTests + "]";
     }
 }
diff --git a/devtools/cli/src/test/java/io/quarkus/cli/CliDriver.java b/devtools/cli/src/test/java/io/quarkus/cli/CliDriver.java
index d7c30449ce7..6c487e42948 100644
--- a/devtools/cli/src/test/java/io/quarkus/cli/CliDriver.java
+++ b/devtools/cli/src/test/java/io/quarkus/cli/CliDriver.java
@@ -306,11 +306,12 @@ public static Result invokeExtensionRemoveNonexistent(Path projectRoot) throws E
     }
 
     public static Result invokeValidateDryRunBuild(Path projectRoot) throws Exception {
-        Result result = execute(projectRoot, "build", "-e", "-B", "--clean", "--dryrun",
+        Result result = execute(projectRoot, "build", "-e", "-B", "--dryrun",
                 "-Dproperty=value1", "-Dproperty2=value2");
         Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
                 "Expected OK return code. Result:\\n" + result);
-        System.out.println(result.stdout);
+        Assertions.assertTrue(result.stdout.contains("Command line"),
+                "--dry-run should echo command line");
         return result;
     }
 
diff --git a/devtools/cli/src/test/java/io/quarkus/cli/CliNonProjectTest.java b/devtools/cli/src/test/java/io/quarkus/cli/CliNonProjectTest.java
index 100136eae4c..51e2792d7d1 100644
--- a/devtools/cli/src/test/java/io/quarkus/cli/CliNonProjectTest.java
+++ b/devtools/cli/src/test/java/io/quarkus/cli/CliNonProjectTest.java
@@ -58,7 +58,6 @@ public void testBuildOutsideOfProject() throws Exception {
         CliDriver.Result result = CliDriver.execute(workspaceRoot, "build", "-e");
         Assertions.assertEquals(CommandLine.ExitCode.USAGE, result.exitCode,
                 "'quarkus build' should fail outside of a quarkus project directory:\\n" + result);
-        System.out.println(result);
     }
 
     @Test
@@ -66,7 +65,6 @@ public void testDevOutsideOfProject() throws Exception {
         CliDriver.Result result = CliDriver.execute(workspaceRoot, "dev", "-e");
         Assertions.assertEquals(CommandLine.ExitCode.USAGE, result.exitCode,
                 "'quarkus dev' should fail outside of a quarkus project directory:\\n" + result);
-        System.out.println(result);
     }
 
     @Test
diff --git a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectGradleTest.java b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectGradleTest.java
index 6ad76fc1160..6c05469a152 100644
--- a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectGradleTest.java
+++ b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectGradleTest.java
@@ -179,6 +179,47 @@ public void testExtensionList() throws Exception {
                 "Expected OK return code. Result:\\n" + result);
     }
 
+    @Test
+    public void testBuildOptions() throws Exception {
+        CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "--gradle", "-e", "-B", "--verbose");
+        Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
+
+        // 1 --clean --tests --native --offline
+        result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
+                "--clean", "--tests", "--native", "--offline");
+
+        Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
+                "Expected OK return code. Result:\\n" + result);
+
+        Assertions.assertTrue(result.stdout.contains(" clean"),
+                "gradle command should specify 'clean'\\n" + result);
+
+        Assertions.assertFalse(result.stdout.contains("-x test"),
+                "gradle command should not specify '-x test'\\n" + result);
+
+        Assertions.assertTrue(result.stdout.contains("-Dquarkus.package.type=native"),
+                "gradle command should specify -Dquarkus.package.type=native\\n" + result);
+
+        Assertions.assertTrue(result.stdout.contains("--offline"),
+                "gradle command should specify --offline\\n" + result);
+
+        // 2 --no-clean --no-tests
+        result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
+                "--no-clean", "--no-tests");
+
+        Assertions.assertFalse(result.stdout.contains(" clean"),
+                "gradle command should not specify 'clean'\\n" + result);
+
+        Assertions.assertTrue(result.stdout.contains("-x test"),
+                "gradle command should specify '-x test'\\n" + result);
+
+        Assertions.assertFalse(result.stdout.contains("native"),
+                "gradle command should not specify native\\n" + result);
+
+        Assertions.assertFalse(result.stdout.contains("offline"),
+                "gradle command should not specify offline\\n" + result);
+    }
+
     @Test
     public void testCreateArgPassthrough() throws Exception {
         Path nested = workspaceRoot.resolve("cli-nested");
diff --git a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectJBangTest.java b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectJBangTest.java
index 0361777ead3..18550990654 100644
--- a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectJBangTest.java
+++ b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectJBangTest.java
@@ -45,6 +45,8 @@ public void testCreateAppDefaults() throws Exception {
                 "Generated source should reference resteasy. Found:\\n" + source);
 
         result = CliDriver.invokeValidateDryRunBuild(project);
+        Assertions.assertTrue(result.stdout.contains("-Dproperty=value1 -Dproperty2=value2"),
+                "result should contain '-Dproperty=value1 -Dproperty2=value2':\\n" + result.stdout);
 
         CliDriver.invokeValidateBuild(project);
     }
@@ -113,6 +115,45 @@ public void testCreateCliDefaults() throws Exception {
                 "Expected OK return code. Result:\\n" + result);
     }
 
+    @Test
+    public void testBuildOptions() throws Exception {
+        CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "--jbang", "-e", "-B", "--verbose");
+        Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
+
+        // 1 --clean --tests --native --offline
+        result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
+                "--clean", "--tests", "--native", "--offline");
+
+        Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
+                "Expected OK return code. Result:\\n" + result);
+
+        Assertions.assertTrue(result.stdout.contains("--fresh"),
+                "jbang command should specify '--fresh'\\n" + result);
+
+        // presently no support for --tests or --no-tests
+
+        Assertions.assertTrue(result.stdout.contains("--native"),
+                "jbang command should specify --native\\n" + result);
+
+        Assertions.assertTrue(result.stdout.contains("--offline"),
+                "jbang command should specify --offline\\n" + result);
+
+        // 2 --no-clean --no-tests
+        result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
+                "--no-clean", "--no-tests");
+
+        Assertions.assertFalse(result.stdout.contains("--fresh"),
+                "jbang command should not specify '--fresh'\\n" + result);
+
+        // presently no support for --tests or --no-tests
+
+        Assertions.assertFalse(result.stdout.contains("native"),
+                "jbang command should not specify native\\n" + result);
+
+        Assertions.assertFalse(result.stdout.contains("offline"),
+                "jbang command should not specify offline\\n" + result);
+    }
+
     void validateBasicIdentifiers(Path project, String group, String artifact, String version) throws Exception {
         Assertions.assertTrue(project.resolve("README.md").toFile().exists(),
                 "README.md should exist: " + project.resolve("README.md").toAbsolutePath().toString());
diff --git a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectMavenTest.java b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectMavenTest.java
index 44796ca824f..284ccbc3863 100644
--- a/devtools/cli/src/test/java/io/quarkus/cli/CliProjectMavenTest.java
+++ b/devtools/cli/src/test/java/io/quarkus/cli/CliProjectMavenTest.java
@@ -114,6 +114,50 @@ public void testExtensionList() throws Exception {
                 "Expected error return code. Result:\\n" + result);
     }
 
+    @Test
+    public void testBuildOptions() throws Exception {
+        CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "app", "-e", "-B", "--verbose");
+        Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode, "Expected OK return code." + result);
+
+        // 1 --clean --tests --native --offline
+        result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
+                "--clean", "--tests", "--native", "--offline");
+        Assertions.assertEquals(CommandLine.ExitCode.OK, result.exitCode,
+                "Expected OK return code. Result:\\n" + result);
+
+        Assertions.assertTrue(result.stdout.contains(" clean"),
+                "mvn command should specify 'clean'\\n" + result);
+
+        Assertions.assertFalse(result.stdout.contains("-DskipTests"),
+                "mvn command should not specify -DskipTests\\n" + result);
+        Assertions.assertFalse(result.stdout.contains("-Dmaven.test.skip=true"),
+                "mvn command should not specify -Dmaven.test.skip=true\\n" + result);
+
+        Assertions.assertTrue(result.stdout.contains("-Dnative"),
+                "mvn command should specify -Dnative\\n" + result);
+
+        Assertions.assertTrue(result.stdout.contains("--offline"),
+                "mvn command should specify --offline\\n" + result);
+
+        // 2 --no-clean --no-tests
+        result = CliDriver.execute(project, "build", "-e", "-B", "--dry-run",
+                "--no-clean", "--no-tests");
+
+        Assertions.assertFalse(result.stdout.contains(" clean"),
+                "mvn command should not specify 'clean'\\n" + result);
+
+        Assertions.assertTrue(result.stdout.contains("-DskipTests"),
+                "mvn command should specify -DskipTests\\n" + result);
+        Assertions.assertTrue(result.stdout.contains("-Dmaven.test.skip=true"),
+                "mvn command should specify -Dmaven.test.skip=true\\n" + result);
+
+        Assertions.assertFalse(result.stdout.contains("-Dnative"),
+                "mvn command should not specify -Dnative\\n" + result);
+
+        Assertions.assertFalse(result.stdout.contains("--offline"),
+                "mvn command should not specify --offline\\n" + result);
+    }
+
     @Test
     public void testCreateCliDefaults() throws Exception {
         CliDriver.Result result = CliDriver.execute(workspaceRoot, "create", "cli", "-e", "-B", "--verbose");