Skip to content

Instantly share code, notes, and snippets.

@JYCabello
Last active July 5, 2022 14:11
Show Gist options
  • Save JYCabello/49563c1684500aba2da1fc0167bc5998 to your computer and use it in GitHub Desktop.
Save JYCabello/49563c1684500aba2da1fc0167bc5998 to your computer and use it in GitHub Desktop.
PowerShell script to create a gradle project and open it with idea
function Idea {
param (
$PROJECT
)
$IDEA_PATH="YOURPATHTOIDEA\bin\idea64.exe"
Invoke-Expression "& '$IDEA_PATH' $PROJECT"
}
function CloneIdea {
param (
$URL
)
git clone $URL
$PROJECT_NAME_REGEX = '(?:git@|https://)github.com.*/(.*).git'
$FOUND = $URL -match $PROJECT_NAME_REGEX
if ($FOUND) {
Set-Location $matches[1]
Idea .
}
}
function CreateGradleProject {
param (
$PROJECT_NAME
)
if (-Not ("$PROJECT_NAME"))
{
Write-Output "Please specify a project name"
exit 1
}
Write-Output Creating Gradle project in $PWD/$PROJECT_NAME...
mkdir -p "$PROJECT_NAME/src/test/resources"
mkdir -p "$PROJECT_NAME/src/test/java"
mkdir -p "$PROJECT_NAME/src/main/resources"
mkdir -p "$PROJECT_NAME/src/main/java"
$BuildGradle = "
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
test {
useJUnitPlatform()
}
"
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
New-Item -Name "$PROJECT_NAME/build.gradle" -ItemType File
[System.IO.File]::WriteAllLines("$PWD/$PROJECT_NAME/build.gradle", $BuildGradle, $Utf8NoBomEncoding)
$GitIgnore = ".idea
.gradle
*.iml
*.ipr
*.iws
out
build"
New-Item -Name "$PROJECT_NAME/.gitignore" -ItemType File
[System.IO.File]::WriteAllLines("$PWD/$PROJECT_NAME/.gitignore", $GitIgnore, $Utf8NoBomEncoding)
$SettingsGradle = "rootProject.name = `"$PROJECT_NAME`""
New-Item -Name "$PROJECT_NAME/settings.gradle" -ItemType File
[System.IO.File]::WriteAllLines("$PWD/$PROJECT_NAME/settings.gradle", $SettingsGradle, $Utf8NoBomEncoding)
Set-Location $PROJECT_NAME
git init
git add -- build.gradle .gitignore settings.gradle
git commit -m "Added build script and .gitignore"
Write-Output "All done. You can now import the project into your IDE."
Idea .
}
@JYCabello
Copy link
Author

JYCabello commented Jul 5, 2022

One of the folders in my IDEA_PATH has a space in it. When I tried running this script, the space was causing an issue, so I changed line 6 slightly to get the script to run Invoke-Expression "& '$IDEA_PATH' $PROJECT"

Thanks! Added the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment