Skip to content

Instantly share code, notes, and snippets.

@dvsingh9
Last active June 22, 2023 08:55
Show Gist options
  • Save dvsingh9/571ef7956ef336ab21cb97ff0cda3567 to your computer and use it in GitHub Desktop.
Save dvsingh9/571ef7956ef336ab21cb97ff0cda3567 to your computer and use it in GitHub Desktop.
# This power shell script can be used to setup developer machine for java and related frameworks
function Install-Chololatey {
Write-Host "Installing Chocolatey ..."
Set-ExecutionPolicy Bypass -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}
function Install-JDK {
choco install openjdk17 -y --version="17.0.2" --allow-downgrade
RefreshEnv
java -version
}
function Install-Maven {
$mavenVersion = "3.8.6"
choco uninstall maven -f -y
choco install maven -y --version=$mavenVersion --allow-downgrade
Write-Host "Setting up M2_HOME and MAVEN_HOME environement variables..."
[Environment]::SetEnvironmentVariable("M2_HOME", "C:\ProgramData\chocolatey\lib\maven\apache-maven-$mavenVersion", "Machine")
[Environment]::SetEnvironmentVariable("MAVEN_HOME", "C:\ProgramData\chocolatey\lib\maven\apache-maven-$mavenVersion", "Machine")
[Environment]::SetEnvironmentVariable("MAVEN_OPTS", "-Djava.io.tmpdir=C:\Dev\Temp\Java", "Machine")
Write-Host "Copying maven settings.xml to .m2"
$CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$CurrentUserName = $CurrentUser.split("\")[1]
#configuring maven to use my custom settings.xml
Copy-Item -Path infrastructure/maven/settings.xml -Destination C:\Users\$CurrentUserName\.m2\settings.xml
RefreshEnv
}
#script starts here
If(Test-Path -Path "$env:ProgramData\Chocolatey") {
Install-JDK
Install-Maven
}
Else {
Install-Chololatey
Install-JDK
Install-Maven
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment