Can you remember?

camerainstallingGradleWineI wrote about a special application for diabetic people I started to create. Now I have just decided to refactor the whole application. I redesigned the class hierarchy, the look of the GUI, the functionality etc. I wanted to try the newest version of eclipse, codename luna. After solving a problem I managed to start it.

 

I also downloaded newest java development kit version 7u67 and 8u20, gradle version 2.0, joda-time (will be needed later) and I collected some useful eclipse plugins as well. EGit, Green UML, ObjectAid, GitHub extensions, Gradle IDE.

My new eclipse environment is ready now.

I created new git repository for my brand new and very sexy project. This is a way how we can set our system up for using git:

mkdir myProject.git
cd myProject.git
git --bare init

After this it is good to make somewhere a place where we can store git controlled files:

git clone ssh://username@hostname/absolute/path/myProject.git projectNameOnMyLocalPlace

Ok, we have knowledge of git, but we have to know what other tools we need for the project. Because I knew that one of them is gradle, I opened a bottle of Dornfelder rosé and started to read the online documentation about installing gradle and setting its filesystem up.
After I downloaded gradle and unpacked it I had to set and export GRADLE_HOME and expand the PATH environment variable with gradle bin directory. I checked that everything was ok:

gradle -version
------------------------------------------------------------
Gradle 2.0
------------------------------------------------------------
Build time:   2014-07-01 07:45:34 UTC
Build number: none
Revision:     b6ead6fa452dfdadec484059191eb641d817226c
Groovy:       2.3.3
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.7.0_67 (Oracle Corporation 24.65-b04)
OS:           Linux 3.2.0-4-amd64 amd64

Let’s create a temporary directory just for fun and for trying gradle:

mkdir tempDir
cd tempDir
gradle init --type java-library
gradle build

Great! Now you can see a sample gradle directory structure!

I do not know how it works, or what it does. Therefore I have to investigate the features of it.
And I did it.

This is the result of investigating.

I created this build.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
//apply plugin: 'application'
//mainClassName = "org.gradle.sample.Main"

defaultTasks 'init'

task createGitKeepFiles << {
    def f1 = new File('src/main/java/gitkeep')
    f1.text = ''
    f1 = new File('src/main/resources/gitkeep')
    f1.text = 'a'
    f1 = new File('src/test/java/gitkeep')
    f1.text = ''
    f1 = new File('src/test/resources/gitkeep')
    f1.text = ''
}

def libDir = new File('lib/test')

task makeLibDir << {
    libDir.mkdirs()
}

repositories {
    flatDir(dirs: 'lib')
}

dependencies {
    testCompile fileTree('lib/test')
    compile 'joda-time:joda-time:2.4'
}

task copyTask(type: Copy) {
    description 'something has to be inside src and lib dirs because of behaviour of git'
    from '../deps'
    into 'lib'
    include '**/*.jar'
    exclude '**/*.txt'
}

task init {
    dependsOn 'makeLibDir'
    dependsOn 'copyTask'
    dependsOn 'eclipse'
    dependsOn check
    dependsOn 'createGitKeepFiles'
}

task initSourceFolders {
    description 'creates std file structure for java, test and resources'
    sourceSets*.java.srcDirs*.each { it.mkdirs() }
    sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}

jar {
    description 'creates jar; basename: cHCalculator, version: 0.0.1'
    baseName = 'cHCalculator'
    version =  '0.0.1'
}

And use this command to create file system structure.

gradle

The ‘lib’ directory is the place where I store jar dependencies i.e. joda time jar, junit jar etc. So I created my building.gradle to be able to make lib dir and copy some needed files to there. Gradle build script also creates file structure for developing process. I mean

src/main/java
src/main/resources
src/test/java
src/test/resources

Gradle likes this structure. And so do I. These directories are empty now and that is not good for us because git ignores empty dirs so it is impossible to push ‘em. The solution is embedded in the build script. Every leaf-element dirs have to contain a single file at least to get git to deal with them all.
Let’s make this to be git controlled!
Somewhere on the local file system or on your network create a bare git repository.

git --bare init myCentralGitBareRepo.git

Inside the gradle created root directory do the following:

git init
git remote add origin 
git add .
git commit -m 'initial commit'
git push -u origin master

If you or someone else wants to use the git controlled code base then use the following to get the files:

git clone <git/repo/path> localDir4gitOptional

I put everything I did into eclipse.

I also created a slide show movie about the process:

Another way to have gradle and git inside eclipse IDE

Advertisements
This entry was posted in gradle, tools and tagged , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s