Repository: quarkusio/quarkus
Issue: Quarkus gradle generateConfig fails

**Describe the bug**
When initialising a quarkus app using the gradle build tool using the following guide:
https://quarkus.io/guides/gradle-tooling

The gradle task fails to do so.

**Expected behavior**
It should create an application.properties file

**Actual behavior**
You get the following error when trying to generate a config file:
```
./gradlew generateConfig  

> Task :generateConfig FAILED
generating example config

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateConfig'.
> Failed to generate config file

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s
1 actionable task: 1 executed

```

**To Reproduce**
Steps to reproduce the behavior:
According to https://quarkus.io/guides/gradle-tooling:
1. mvn io.quarkus:quarkus-maven-plugin:1.2.1.Final:create \\
    -DprojectGroupId=my-groupId \\
    -DprojectArtifactId=my-artifactId \\
    -DprojectVersion=my-version \\
    -DclassName="org.my.group.MyResource" \\
    -Dextensions="resteasy-jsonb" \\
    -DbuildTool=gradle
2. ./gradlew generateConfig

**Environment:**
 - Output of `uname -a`: Darwin C02X1FKFJG5J 18.7.0 Darwin Kernel Version 18.7.0: Thu Jan 23 06:52:12 PST 2020; root:xnu-4903.278.25~1/RELEASE_X86_64 x86_64
 - Output of `java -version`:
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.242-b08, mixed mode)
 - GraalVM version (if different from Java): n/a
 - Quarkus version or git rev: n/a
 - Build tool (ie. output of `mvnw --version`): mvn --version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T19:33:14+01:00)
Maven home: /usr/local/Cellar/maven@3.5/3.5.4_1/libexec
Java version: 13.0.2, vendor: N/A, runtime: /usr/local/Cellar/openjdk/13.0.2+8_2/libexec/openjdk.jdk/Contents/Home
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"

Changed files:
devtools/maven/src/main/java/io/quarkus/maven/GenerateConfigMojo.java
devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateConfig.java
core/deployment/src/main/java/io/quarkus/runner/bootstrap/GenerateConfigTask.java

diff --git a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/GenerateConfigTask.java b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/GenerateConfigTask.java
index a458071d42d..f4ea790b8bd 100644
--- a/core/deployment/src/main/java/io/quarkus/runner/bootstrap/GenerateConfigTask.java
+++ b/core/deployment/src/main/java/io/quarkus/runner/bootstrap/GenerateConfigTask.java
@@ -7,6 +7,8 @@
 import java.nio.file.StandardOpenOption;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
+import java.util.function.BiConsumer;
 import java.util.function.Consumer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -25,17 +27,15 @@
  *
  * @author Stuart Douglas
  */
-public class GenerateConfigTask {
+public class GenerateConfigTask implements BiConsumer<CuratedApplication, Map<String, Object>> {
 
     private static final Logger log = Logger.getLogger(GenerateConfigTask.class);
 
-    private final Path configFile;
+    public static final String CONFIG_FILE = "config-file";
 
-    public GenerateConfigTask(Path configFile) {
-        this.configFile = configFile;
-    }
-
-    public Path run(CuratedApplication application) {
+    @Override
+    public void accept(CuratedApplication application, Map<String, Object> stringObjectMap) {
+        Path configFile = (Path) stringObjectMap.get(CONFIG_FILE);
         //first lets look for some config, as it is not on the current class path
         //and we need to load it to run the build process
         try {
@@ -89,7 +89,6 @@ public void accept(BuildExecutionBuilder buildExecutionBuilder) {
         } catch (Exception e) {
             throw new RuntimeException("Failed to generate config file", e);
         }
-        return configFile;
     }
 
     private String formatDocs(String docs) {
@@ -154,4 +153,5 @@ private String configify(String group) {
         }
         return ret.toString();
     }
+
 }
diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateConfig.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateConfig.java
index 9edbca504a9..e761a479ae7 100644
--- a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateConfig.java
+++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusGenerateConfig.java
@@ -1,6 +1,7 @@
 package io.quarkus.gradle.tasks;
 
 import java.io.File;
+import java.util.Collections;
 
 import org.gradle.api.GradleException;
 import org.gradle.api.tasks.Input;
@@ -39,6 +40,7 @@ public void buildQuarkus() {
         getLogger().lifecycle("generating example config");
 
         final AppArtifact appArtifact = extension().getAppArtifact();
+        appArtifact.setPath(extension().appJarOrClasses());
         final AppModelResolver modelResolver = extension().getAppModelResolver();
         if (extension().resourcesDir().isEmpty()) {
             throw new GradleException("No resources directory, cannot create application.properties");
@@ -49,14 +51,19 @@ public void buildQuarkus() {
         if (name == null || name.isEmpty()) {
             name = "application.properties.example";
         }
-        try (CuratedApplication bootstrap = QuarkusBootstrap.builder(getProject().getBuildDir().toPath())
-                .setMode(QuarkusBootstrap.Mode.PROD)
+        try (CuratedApplication bootstrap = QuarkusBootstrap.builder(appArtifact.getPath())
+                .setBaseClassLoader(getClass().getClassLoader())
                 .setAppModelResolver(modelResolver)
-                .setBuildSystemProperties(getBuildSystemProperties(appArtifact))
-                .build()
-                .bootstrap()) {
-            GenerateConfigTask ct = new GenerateConfigTask(new File(target, name).toPath());
-            ct.run(bootstrap);
+                .setTargetDirectory(getProject().getBuildDir().toPath())
+                .setBaseName(extension().finalName())
+                .setAppArtifact(appArtifact)
+                .setLocalProjectDiscovery(false)
+                .setIsolateDeployment(true)
+                //.setConfigDir(extension().outputConfigDirectory().toPath())
+                //.setTargetDirectory(extension().outputDirectory().toPath())
+                .build().bootstrap()) {
+            bootstrap.runInAugmentClassLoader(GenerateConfigTask.class.getName(),
+                    Collections.singletonMap(GenerateConfigTask.CONFIG_FILE, new File(target, name).toPath()));
             getLogger().lifecycle("Generated config file " + name);
         } catch (BootstrapException e) {
             throw new RuntimeException(e);
diff --git a/devtools/maven/src/main/java/io/quarkus/maven/GenerateConfigMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/GenerateConfigMojo.java
index f4e89b5d8d6..bb9390e7c0f 100644
--- a/devtools/maven/src/main/java/io/quarkus/maven/GenerateConfigMojo.java
+++ b/devtools/maven/src/main/java/io/quarkus/maven/GenerateConfigMojo.java
@@ -3,6 +3,7 @@
 import java.io.File;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.maven.model.Resource;
@@ -120,8 +121,8 @@ public void execute() throws MojoExecutionException {
                     name = "application.properties.example";
                 }
                 Path configFile = new File(target, name).toPath();
-                GenerateConfigTask generateConfigTask = new GenerateConfigTask(configFile);
-                generateConfigTask.run(curatedApplication);
+                curatedApplication.runInAugmentClassLoader(GenerateConfigTask.class.getName(),
+                        Collections.singletonMap(GenerateConfigTask.CONFIG_FILE, configFile));
 
             } catch (Exception e) {
                 throw new MojoExecutionException("Failed to generate config file", e);