Files
openidea/generators/java.toml
T
l0ng-ai 605d5f4985 feat(new-project): project generators for mainstream languages and frameworks (#2689)
File › New Project offers 38 generators grouped by language (Java, Spring Boot, Quarkus, Micronaut, Kotlin, Ktor, Scala, Python/Django/FastAPI/Flask, Node/Vite/Next.js/Nuxt/Angular/SvelteKit/Astro/NestJS/Express, Go, Rust, C/C++, Zig, .NET, PHP/Laravel/Symfony, Ruby/Rails, Dart/Flutter, Swift, Elixir/Phoenix, Haskell, static website, empty). Each is a declaration in generators/<id>.toml run by the new ide-scaffold crate: built-in templates, the framework's official CLI run non-interactively, or a project service zip (Spring Initializr, code.quarkus.io, Micronaut Launch) whose metadata becomes form fields. Projects are built in a staging directory and moved into place only on success. The dialog renders each form from its schema, flags missing toolchains with install hints and streams progress; created projects open trusted. New Project is also on the welcome screen and the title bar project menu.

Closes #709
2026-11-11 17:22:57 +08:00

170 lines
3.4 KiB
TOML

id = "java"
name = "Java"
group = "Java"
icon = "project-java"
description = "A plain Java application built with Maven or Gradle."
[[fields]]
id = "build"
label = "Build system:"
type = "choice"
segmented = true
options = [{ value = "maven", label = "Maven" }, { value = "gradle", label = "Gradle" }]
default = "maven"
[[fields]]
id = "jdk"
label = "JDK:"
type = "sdk"
sdk = "jdk"
[[fields]]
id = "release"
label = "Java version:"
type = "choice"
options = ["25", "21", "17", "11"]
default = "21"
[[fields]]
id = "group"
label = "Group:"
type = "text"
pattern = '^[A-Za-z_][\w]*(\.[A-Za-z_][\w]*)*$'
default = "com.example"
[[fields]]
id = "artifact"
label = "Artifact:"
type = "text"
pattern = '^[A-Za-z0-9_.-]+$'
default = "{{name|kebab}}"
[[fields]]
id = "package"
label = "Package:"
type = "text"
pattern = '^[A-Za-z_][\w]*(\.[A-Za-z_][\w]*)*$'
default = "{{group}}.{{artifact|ident}}"
[[fields]]
id = "sample"
label = "Add sample code"
type = "checkbox"
default = "true"
[[files]]
path = "pom.xml"
when = { build = "maven" }
content = '''
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>{{group}}</groupId>
<artifactId>{{artifact}}</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.release>{{release}}</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.13.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.4</version>
</plugin>
</plugins>
</build>
</project>
'''
[[files]]
path = "settings.gradle.kts"
when = { build = "gradle" }
content = '''
rootProject.name = "{{artifact}}"
'''
[[files]]
path = "build.gradle.kts"
when = { build = "gradle" }
content = '''
plugins {
application
}
group = "{{group}}"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(platform("org.junit:junit-bom:5.13.4"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
tasks.withType<JavaCompile> {
options.release = {{release}}
options.encoding = "UTF-8"
}
application {
mainClass = "{{package}}.Main"
}
tasks.test {
useJUnitPlatform()
}
'''
[[files]]
path = "src/main/java/{{package|path}}/Main.java"
when = { sample = "true" }
content = '''
package {{package}};
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
'''
[[files]]
path = ".gitignore"
content = '''
target/
build/
.gradle/
*.class
.idea/
'''
[[after]]
label = "Generating the Gradle wrapper"
program = "gradle"
args = ["wrapper", "--no-daemon", "-q"]
when = { build = "gradle" }
env = { JAVA_HOME = "{{jdk}}" }
optional = true
[settings.java]
jdk = "{{jdk}}"