Permalink
Browse files

Initial commit.

  • Loading branch information...
1 parent 2d973de commit c146b4db832f7832f12365d105c75b9240d61821 @anagrius anagrius committed Feb 23, 2011
View
136 README.md
@@ -0,0 +1,136 @@
+Introduction
+============
+
+This project is meant as starting point for Trifork projects that use Gradle
+as build-system. It is a good idea to become familiar with Gradle, and the
+[Gradle Userguide](http://gradle.org/documentation.html) is a very good
+reference.
+
+To get started make a git repository and add this repository as a remote:
+
+ git remote add template git://github.com/trifork/gradle-template.git
+
+That way you can also easily get any future additions:
+
+ git pull template master
+
+The template contains two example sub-projects, one Java and one Scala.
+
+Suggestions and patches (or pull requests) are very welcome. If you encounter
+any bugs please make an issue on Github.
+
+Build Customization
+-------------------
+
+Take a look in 'gradle.properties', 'build.gradle', 'settings.gradle' and in
+the config-directory to customize the build to fit your project.
+
+There are very few things that actually need to be changed in the build
+configuration – at least to start out with.
+But there are though a couple of properties you need to change in
+'gradle.properties'.
+
+First off, you will have to change the name of the `projectName` and
+`nextReleaseVersion` properties. These properties are defined in
+`gradle.properties` file. The properties are described in greater detail in
+the file itself.
+
+If you do not want to use Jira or use some other SCM than Git you will also
+have to change some settings in the `config/deployment.groovy` file.
+
+Coding standards and formatting is checked using Checkstyle. You can edit them
+to fit your project in `config/checkstyle/checkstyle.xml`.
+
+Dependency Management
+---------------------
+
+It is a good idea to keep a list of dependencies you use in several
+sub-projects in the `config/libraries.groovy` file. That way you can keep
+versions consistent. There is of course nothing that is stopping your from
+declaring dependencies on an ad-hoc basis in your sub-projects. But this can
+quickly get out of hand for larger projects.
+
+Plugins
+-------
+
+Gradle has a good plugin system. By default Gradle comes with a lot of handy
+plugins, but they are quite general and need some customization. Therefore
+there is a set plugin specificly made for Trifork projects.
+
+By default only the `deployment` plugin is added. It helps you use the
+Trifork nexus server correctly and use a consistent scheme for deployment of
+artifacts, both class and source files.
+
+All the plugins are described in the Plugin Project's README. You can find it
+[here](https://github.com/trifork/gradle-plugins).
+
+Releases & Snapshots
+--------------------
+
+When you apply the deployment-plugin you get a few extra tasks to help you
+share your artifacts.
+
+It is important to have a well-defined and consistent way of sharing jar files
+and other artifacts. Maven repos are the de-facto standard for artifact
+sharing and by using it you get a high degree of interoperability between
+build systems.
+
+When using the deployment-plugin it is important to manage your build version.
+The property `version` should always update it when you have made a release to
+the repository. It is defined in the 'gradle.properties' file.
+
+You will only be able to release an artifact of a given version once. If you
+try to redeploy a release artifact, the deployment will fail (as it should).
+If you have made a mistake in a release, the only thing you can do is to
+confess you messed up and make a new release with a version bump.
+
+Deploy a release artifact:
+
+ gradle deployRelease
+
+While releases are fine when you are actually finished with an iteration or
+some other milestone, it is not always convenient to use release artifacts
+during active development. Therefore when you want to share your diamonds in
+the rough, you can use _Snapshot_ versions. Snapshots of a given version can
+be deployed with any number of times. For people familiar with Ivy, snapshots
+can be used as a 'latest integration' dependencies.
+
+Deploy a snapshot artifact:
+
+ gradle deploySnapshot
+
+When making a release it is important to make sure that you don't
+depend on any snapshot artifacts. Since snapshots change over time, future
+snapshot versions will potentially break your release (which is bad).
+
+So make sure you have no '-SNAPSHOT' dependencies when you call
+`deployRelease` or at the very least, as few of them as possible.
+
+TODO: In future this check might be automated.
+
+Git Tips
+--------
+
+It is a good idea to check your code before you push anything to other central
+repositories. While you don't necessarily want to run tests and check code for
+every commit you do locally.
+
+You can setup a git command alias to check your code before you push anything.
+
+ git config alias.publish '! gradle check && git push "$@"'
+
+This will allow you to e.g. write:
+
+ git publish origin master
+
+as an alternative to `git push`. Please note that since you will be running
+tests and other code checks this will usually take considerably longer than
+a normal push.
+
+Requirements
+------------
+
+This build setup is made for Gradle 1.0-milestone-1+.
+
+If you want to run the Scala subproject you will need to have install a
+version of Scala.
View
78 build.gradle
@@ -0,0 +1,78 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file is the base build-script for the project. There are additional
+// config files in the 'config'-directory, that handle different aspects of
+// the build and deployment for the project.
+//////////////////////////////////////////////////////////////////////////////
+
+apply plugin: 'java-base'
+
+// Please make sure you read the README.md file before you try to understand
+// what is going on.
+
+allprojects {
+ // You can use 'gradle eclipse' to generate eclipse project files.
+ // You can use 'gradle -t' to see a list of availible tasks.
+ apply plugin: 'eclipse'
+
+ defaultTasks 'build'
+
+ // Usually you will want to add proxy repositories to nexus instead on
+ // adding explicitly here.
+ repositories {
+ mavenLocal()
+ mavenRepo name: 'trifork-releases', urls: 'http://nexus.ci81.trifork.com/content/groups/public/'
+ mavenRepo name: 'trifork-snapshots', urls: 'http://nexus.ci81.trifork.com/content/groups/public-snapshots/'
+ }
+}
+
+subprojects { subproject ->
+
+ // Subproject currently always default to java. This might change in the future.
+ // If you are making WARs take a look at the 'war' plugin.
+ apply plugin: 'java'
+ apply plugin: 'deployment'
+
+ targetCompatibility = '1.6'
+ sourceCompatibility = '1.6'
+
+ // Include references to common dependencies so you can keep
+ // versions consistent accross your sub-projects.
+
+ apply from: 'config/libraries.groovy'
+
+ // Checkstyle source coding standards.
+ // TODO: These setting are a bit verbose, but
+ // the implementation seems to be a bit broken (in Gradle 0.9.2).
+ apply plugin: 'code-quality'
+ checkstyleConfigDir = "$rootDir/config/checkstyle"
+ checkstyleConfigFileName = new File(checkstyleConfigDir, "checkstyle.xml")
+ checkstyleProperties.checkstyleConfigDir = checkstyleConfigDir
+
+ // Shared dependencies for all subprojects.
+ // Logging is a common shared dependency.
+ dependencies {
+ testCompile libraries.testng
+ }
+
+ // Add some extra memory for testing, this is usually useful.
+ test {
+ maxHeapSize = "1024m"
+ }
+}
+
+dependsOnChildren()
+
+// The following is section is adds the plugins from
+// https://github.com/trifork/gradle-plugins.
+
+buildscript {
+ repositories {
+ mavenLocal()
+ mavenRepo name: 'trifork-releases', urls: 'http://nexus.ci81.trifork.com/content/groups/public/'
+ mavenRepo name: 'trifork-snapshots', urls: 'http://nexus.ci81.trifork.com/content/groups/public-snapshots/'
+
+ }
+ dependencies {
+ classpath 'com.trifork:gradle-plugins:0.1.0'
+ }
+}
View
95 config/checkstyle/checkstyle.xml
@@ -0,0 +1,95 @@
+<!--
+ ~ Copyright 2010 the original author or authors.
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<!DOCTYPE module PUBLIC
+ "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
+ "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
+<module name="Checker">
+ <module name="TreeWalker">
+ <!-- Blocks -->
+ <module name="EmptyBlock">
+ <property name="option" value="stmt"/>
+ <property name="tokens" value="LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_IF,LITERAL_FOR,LITERAL_TRY,LITERAL_WHILE,INSTANCE_INIT,STATIC_INIT"/>
+ </module>
+ <module name="EmptyBlock">
+ <property name="option" value="text"/>
+ <property name="tokens" value="LITERAL_CATCH"/>
+ </module>
+ <module name="AvoidNestedBlocks"/>
+
+ <!-- Braces -->
+ <module name="LeftCurly"/>
+ <module name="RightCurly"/>
+ <module name="NeedBraces"/>
+
+ <!-- Whitespace -->
+ <module name="GenericWhitespace"/>
+ <module name="EmptyForInitializerPad"/>
+ <module name="EmptyForIteratorPad"/>
+ <module name="MethodParamPad"/>
+ <module name="NoWhitespaceBefore"/>
+ <module name="NoWhitespaceAfter"/>
+ <module name="OperatorWrap"/>
+ <module name="ParenPad"/>
+ <module name="TypecastParenPad"/>
+ <module name="WhitespaceAfter">
+ <property name="tokens" value="COMMA, SEMI"/>
+ </module>
+ <!--<module name="WhitespaceAround">-->
+ <!-- everything except { and } -->
+ <!--<property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LE, LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN, TYPE_EXTENSION_AND"/>-->
+ <!--</module>-->
+
+ <!-- Coding -->
+ <module name="CovariantEquals"/>
+ <module name="DefaultComesLast"/>
+ <module name="EmptyStatement"/>
+ <module name="EqualsHashCode"/>
+ <module name="ExplicitInitialization"/>
+ <module name="MultipleVariableDeclarations"/>
+ <module name="NoClone"/>
+ <module name="NoFinalizer"/>
+ <module name="RedundantThrows">
+ <property name="allowUnchecked" value="true"/>
+ </module>
+ <module name="SimplifyBooleanExpression"/>
+ <module name="SimplifyBooleanReturn"/>
+ <module name="StringLiteralEquality"/>
+ <module name="UnnecessaryParentheses"/>
+
+ <!-- Design -->
+ <module name="InterfaceIsType"/>
+
+ <!-- Imports -->
+ <module name="RedundantImport"/>
+ <module name="UnusedImports"/>
+
+ <!-- Naming -->
+ <module name="ClassTypeParameterName"/>
+ <module name="ConstantName"/>
+ <module name="LocalFinalVariableName"/>
+ <module name="LocalVariableName"/>
+ <module name="MemberName"/>
+ <module name="MethodName"/>
+ <module name="MethodTypeParameterName"/>
+ <module name="PackageName">
+ <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
+ </module>
+ <module name="ParameterName"/>
+ <module name="StaticVariableName"/>
+ <module name="TypeName"/>
+
+ </module>
+</module>
View
24 config/libraries.groovy
@@ -0,0 +1,24 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file contains a handy list of dependencies' names and versions.
+// This can be used to make sure dependencies are consistently versioned
+// in your projects.
+//////////////////////////////////////////////////////////////////////////////
+
+slf4jVersion = '1.6.1'
+
+libraries = [
+
+ // Javassist
+
+ javassist: 'javassist:javassist:3.12.0.GA',
+
+ // Logging
+
+ slf4j_api: 'org.slf4j:slf4j-api:' + slf4jVersion,
+ jcl_slf4j: 'org.slf4j:jcl-over-slf4j:' + slf4jVersion,
+ log4j_slf4j: 'org.slf4j:log4j-over-slf4j:' + slf4jVersion,
+
+ // Testing
+
+ testng: 'org.testng:testng:5.14.6'
+]
View
22 gradle.properties
@@ -0,0 +1,22 @@
+//////////////////////////////////////////////////////////////////////////////
+// This file contains properties for the build script. While you can write
+// these settings directly into the groovy code. It is a good idea to have
+// a single place for all build settings.
+//////////////////////////////////////////////////////////////////////////////
+
+// The name of the project.
+//
+// Artifacts in subprojects are named by setting the 'artifactId' property in
+// the respective gradle files. This property is use as the group part of the
+// artifact name when deploying to a maven repository.
+
+group = com.trifork.changeme
+
+// The next version of the project that will ne released.
+//
+// It might seem strange to specify the 'next' release version.
+//
+// After a release artifact has been uploaded. It is important to update this
+// property.
+
+version = 0.1.0
View
16 settings.gradle
@@ -0,0 +1,16 @@
+// Declare subprojects in this file.
+// The prefered way is to list them, one per line,
+// as below.
+
+include 'subproject1'
+include 'subproject2'
+
+// To avoid every gradle file being called 'build.gradle',
+// subprojects are required to name theirs
+// e.g. subproject1/subproject1.gradle.
+
+rootProject.children.each { project ->
+ project.buildFileName = "${project.name}.gradle"
+ assert project.projectDir.isDirectory()
+ assert project.buildFile.isFile()
+}
View
6 subproject1/gradle.properties
@@ -0,0 +1,6 @@
+//////////////////////////////////////////////////////////////////////////////
+// If you don't want the produced artifacts to have the same name as the
+// subproject's directory you can set the 'artifactId' property like below.
+//////////////////////////////////////////////////////////////////////////////
+
+artifactId = changeme-core
View
7 subproject1/src/main/java/com/trifork/Main.java
@@ -0,0 +1,7 @@
+package com.trifork;
+
+public class Main {
+ public static void main(String[] args) {
+ System.out.println("Hello from Subproject 1!");
+ }
+}
View
1 subproject1/subproject1.gradle
@@ -0,0 +1 @@
+apply plugin: 'war'
View
5 subproject2/src/main/scala/Main.scala
@@ -0,0 +1,5 @@
+object Main {
+ def main(args: Array[String]) {
+ println("Hello from subproject 2!")
+ }
+}
View
17 subproject2/subproject2.gradle
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+// This project is a simple scala project example. Remember that you need
+// scala installed to actually run it.
+//////////////////////////////////////////////////////////////////////////////
+
+apply plugin: 'scala'
+
+def SCALA_VERSION = "2.8.1"
+
+dependencies {
+ // Libraries needed to run the scala tools.
+ scalaTools 'org.scala-lang:scala-compiler:' + SCALA_VERSION
+ scalaTools 'org.scala-lang:scala-library:' + SCALA_VERSION
+
+ // Libraries needed for scala api.
+ compile 'org.scala-lang:scala-library:' + SCALA_VERSION
+}

0 comments on commit c146b4d

Please sign in to comment.