Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@yellowsnow
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yellowsnow/5a54b3dbc4a10c7e4f86 to your computer and use it in GitHub Desktop.
Save yellowsnow/5a54b3dbc4a10c7e4f86 to your computer and use it in GitHub Desktop.
genv : poor man's windows dev environment switcher (Windows 7+)

What’s this?

If you are unlucky like me and you are constrained to work under windows for your groovy / grails / Java development, you certainly miss tools like GVM

This is a poor man’s windows dev environment switcher, based on symbolic links and made for Windows 7 or higher. And yes, it’s a one line command line :)

You are even poorer? you use XP :) Don’t panic, if you don’t have mklink on your windows, check alternatives here Symbolic links on windows

Usage

genv grails 2.4.4
genv groovy 2.3.0
genv gradle 2.1
genv apache-maven 3.2.3

Setup

You can customize and use the example setup file OR Manually:

Define root installation folder for Grails, Groovy, Gradle, Maven, etc. It’s here where you should unzip all of them :

                                                       -----------------------------------------------     |                                               |     -----------------------------------------------     |                                               |     |                           ---------------   |     |  Variable name :          |ENV_SWITCH_ROOT|   |     |                           ---------------   |     |                           ---------------   |     |  Variable value :         |D:\Dev         |   |     |                           --------------   |     |                                               |     -----------------------------------------------+                                                                                                               

Home variables :

GRAILS_HOME -> %ENV_SWITCH_ROOT%\grails-current
GROOVY_HOME -> %ENV_SWITCH_ROOT%\groovy-current
GRADLE_HOME -> %ENV_SWITCH_ROOT%\gradle-current
M2_HOME -> %ENV_SWITCH_ROOT%\apache-maven-current

Making everything executable :

PATH -> %PATH%... %ENV_SWITCH_ROOT%;%GRAILS_HOME%\bin;%GROOVY_HOME%\bin;%GRADLE_HOME%\bin;%M2_HOME%\bin

Bonus

vgrails.bat : Auto set grails version on an existing project

vgrails

getgrailsversion.bat : Display grails version of an existing project

getgrailsversion
@echo off
setlocal
set CANDIDATE=%1%
set VERSION=%2%
set SEPARATOR=-
set CURRENT=current
set SRC=%ENV_SWITCH_ROOT%\%CANDIDATE%%SEPARATOR%%CURRENT%
set DEST=%ENV_SWITCH_ROOT%\%CANDIDATE%%SEPARATOR%%VERSION%
rmdir %SRC%
mklink /D %SRC% %DEST%
Endlocal
@echo off
cat application.properties | grep app.grails.version | cut -d "=" -f2-
setx /M ENV_SWITCH_ROOT D:\dev
setx /M GRAILS_HOME %ENV_SWITCH_ROOT%\grails-current
setx /M GROOVY_HOME %ENV_SWITCH_ROOT%\groovy-current
setx /M GRADLE_HOME %ENV_SWITCH_ROOT%\gradle-current
setx /M M2_HOME %ENV_SWITCH_ROOT%\apache-maven-current
@echo off
for /f "delims=" %%a in ('getgrailsversion') do @set VERSION=%%a
genv grails %VERSION%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment