# Gradle create project within application



## CrashKurs (8. Mrz 2016)

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:

```
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


----------

