Mixing Scala and Java in a Gradle project

This post is basically the twin of an earlier post, which describes the same process for maven.

I had the questionable pleasure of having to convert my existing maven project to Gradle, which is basically almost as bad a maven and a lot slower, but hell, which build tool is perfect anyway?

So with not much further ado, here’s the basic structure:

apply plugin: 'scala'
apply plugin: 'eclipse'
sourceCompatibility = 1.7
version = '1.0'
configurations {
provided
}
configurations.all {
resolutionStrategy {
            force(
            'org.scala-lang:scala-library:2.10.4'
           )
    }
}
jar {
    from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {
        exclude "META-INF/*.SF"
        exclude "META-INF/*.DSA"
        exclude "META-INF/*.RSA"
        exclude "META-INF/license/*"
    }
    manifest {
    attributes( 'Implementation-Version': version,
                'Built-By': System.getProperty('user.name'),
                'Built-Date': new Date(),
                'Built-JDK': System.getProperty('java.version'))
    }
}
repositories {
    mavenCentral()
    maven { url "http://conjars.org/repo/" }
    maven { url "http://repo.typesafe.com/typesafe/releases/" }
}
dependencies {
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    compile "org.apache.flume.flume-ng-sinks:flume-ng-elasticsearch-sink:1.5.0.1"
    testCompile group: 'junit', name: 'junit', version: '4.+'
    
}
test {
    systemProperties 'property': 'value'
}

 

I must confess that this is actually a great deal shorter than the maven equivalent, mainly due to the simplicity of the scala plugin implementation, which also takes care of compiling java classes as well.

The project structure as such follows the basic pattern of maven projects:

src/main/scala
src/main/java
src/main/resources

and pretty much the same for test.

Advertisements
This entry was posted in Uncategorized. 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