Gradle create project within application

CrashKurs

Mitglied
Hey guys,

im currently trying to create a gradle project from java code with the tooling api.
The problem I'm facing is that before i use the GradleConnector to run tasks i have to manually create every file and it's content like the build.gradle and the source directories.

My question is: Is there a build-in class or tooling model from gradle to set up a gradle project and its directories depending on the plugins i have applied? Or do Intellij IDEA and Eclipse have their own classes to create files, setup the project and don't use any gradle specific for this?

Havent' found any documentation in the IDEA gradle plugin or the tooling api.

My current code looks like this:
Java:
File file = new File("C:\\workspace");
        file.mkdirs();
File initScript = new File(file.getAbsolutePath() + "\\build.gradle");
        try {
            initScript.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try(BufferedWriter outputStream = new BufferedWriter(new FileWriter(initScript))) {
            outputStream.write("allprojects {\n" +
                    "   apply plugin: 'groovy'\n" +
                    "   apply plugin: 'java'\n" +
                    "   sourceSets {\n" +
                    "       main {\n" +
                    "           java {\n" +
                    "               \n" +
                    "           }\n" +
                    "       }\n" +
                    "   }\n" +
                    "sourceSets.all {\n" +
                    "    println name\n" +
                    "}\n"  +
                    "   repositories {\n" +
                    "       \n" +
                    "   }\n" +
                    "}");
            outputStream.newLine();
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
ProjectConnection connection = GradleConnector.newConnector()
                .forProjectDirectory(new File("C:\\workspace"))
                .connect();
        try {
            BuildLauncher build = connection.newBuild();
            build.setStandardOutput(System.out);
            build.forTasks("init", "wrapper", "tasks");
            build.run();
        } finally {
            connection.close();
        }

Greetings,
Crashkurs
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
N No Main Manifest Attribute trotz Eintrag bei Gradle Tools - Maven, Gradle, Ant & mehr 1
8u3631984 Gradle und NPM wie strukturieren Tools - Maven, Gradle, Ant & mehr 3
S Gradle kann Lottie Implementation nicht finden Tools - Maven, Gradle, Ant & mehr 5
Gradle build funktioniert nicht Tools - Maven, Gradle, Ant & mehr 10
Moman2022 Hauptklasse kann nicht gefunden werden gradle build Tools - Maven, Gradle, Ant & mehr 3
8u3631984 Gradle nicht benötigte Dependencies finden Tools - Maven, Gradle, Ant & mehr 3
B Gradle Terminal/Console Encoder Tools - Maven, Gradle, Ant & mehr 9
S "Wer" löscht JARs aus meinem Gradle-cache? Tools - Maven, Gradle, Ant & mehr 3
von Spotz Gradle: Warum wird das Plugin nicht geladen? Tools - Maven, Gradle, Ant & mehr 4
8u3631984 Verschachteltes Gradle Projekt Tools - Maven, Gradle, Ant & mehr 0
von Spotz Gradle: Dependencies und Plugins vom root Projekt für die child-Projekte verfügbar machen Tools - Maven, Gradle, Ant & mehr 5
J Gradle signing Plugin Tools - Maven, Gradle, Ant & mehr 0
Y Gradle finished with non-zero exit value 1 mit Gradle Tools - Maven, Gradle, Ant & mehr 1
L Gradle Ein lokales Eclipse Projekt in Gradle dependency einbinden Tools - Maven, Gradle, Ant & mehr 2
8u3631984 Gradle : Baue anderes Modul und packe es in einen Docker Container Tools - Maven, Gradle, Ant & mehr 0
M Was ist besser für den Anfang, Maven oder Gradle? Tools - Maven, Gradle, Ant & mehr 6
P Gradle Dependencies in Module vererben Tools - Maven, Gradle, Ant & mehr 2
J [Gradle] Task Reihenfolge pusblishMaven vor codenarcTest Tools - Maven, Gradle, Ant & mehr 0
J netbeans - jasperreports - gradle - klappt nicht Tools - Maven, Gradle, Ant & mehr 0
sascha-sphw Maven vs Gradle Tools - Maven, Gradle, Ant & mehr 24
L Gradle src-gen zum Classpath hinzufügen Tools - Maven, Gradle, Ant & mehr 0
N Gradle Tools - Maven, Gradle, Ant & mehr 4
W Gradle in Netbeans ... wie? Tools - Maven, Gradle, Ant & mehr 28
N Gradle für Tests 2 Frameworks Tools - Maven, Gradle, Ant & mehr 2
E Gradle Build Tools - Maven, Gradle, Ant & mehr 1
Tom299 (Gradle) Wie die JAR eines 2. Projektes "includieren" Tools - Maven, Gradle, Ant & mehr 1
Psypsy Multi-Projekt mit Gradle Tools - Maven, Gradle, Ant & mehr 1
Kr0e Best practices / Gradle und co Tools - Maven, Gradle, Ant & mehr 7
T Maven Problem by crearting a new project with "mvn archetype:create" Tools - Maven, Gradle, Ant & mehr 2
N Required filename-based automodules detected. Please don't publish this project to a public artifact repository Tools - Maven, Gradle, Ant & mehr 9
P Maven Wie die Maven Project version in JSP page verwenden? Tools - Maven, Gradle, Ant & mehr 2
H Maven Anfängerproblem - No plugin found for prefix 'archetype' in the current project and in the plugin groups Tools - Maven, Gradle, Ant & mehr 25
S Maven project build error (String index out of range: 1) Tools - Maven, Gradle, Ant & mehr 2
ruutaiokwu eclipse web project - warum in den "build"-ordner kompilieren ??? Tools - Maven, Gradle, Ant & mehr 10

Ähnliche Java Themen

Neue Themen


Oben