Skip to content
Snippets Groups Projects
javaproject.gradle 7.15 KiB
Newer Older
  • Learn to ignore specific revisions
  • apply plugin: 'java'
    
    apply plugin: 'project-report'
    
    evaluationDependsOnChildren()
    
    configurations {
        tests  { 
             extendsFrom testRuntime 
    
    }
    
    configurations.all {
        resolutionStrategy.cacheChangingModulesFor 0, 'hours'
    }
    
    
    task wrapper(type: Wrapper) {
    
        gradleVersion = '1.8'
        distributionUrl = "http://svncisd.ethz.ch/repos/cisd/ivy-repository/trunk/gradle/distribution/1.8/gradle-1.8-all.zip"
    
    
    addSource = (sourceCompatibility == org.gradle.api.JavaVersion.VERSION_1_6)
    
    sourceCompatibility='1.6'
    targetCompatibility='1.6'
    
    sourceSets { 
    
        main {
            java {
                srcDirs = ['source/java']
            }
        }
        test {
            java {
                srcDirs = ['sourceTest/java']
            }
            resources {
                srcDirs = ['sourceTest/java']
            }
        }
    
    buildDir = 'targets/gradle'
    
        apply from: '../gradle/repository.gradle'
    
        
        repositories repositoryConfig
        
        dependencies {
            classpath 'cisd:cisd-ant-tasks:+'
    
    repositories repositoryConfig
    
    // Gathering version and revision
    
    def gatheringTask = new ch.systemsx.cisd.ant.task.subversion.GatherRevisionAndVersionTask()
    
    List names = new ArrayList()
    names.add(project.name)
    includeFlat = { String[] projectNames -> names.addAll(Arrays.asList(projectNames)) }
    try {
        apply from: project.file('settings.gradle')
    } catch (Exception e) {
        println "Warning: Couldn't evaluate 'settings.gradle' in ${project.projectDir}. Possible reason: Other statements than 'includeFlat': ${e}"
    
    gatheringTask.setProjectNames(names) 
    
    println "PROJECT: ${project.name}, gather revision for following projects: ${gatheringTask.projectNames}"
    
    def antProject = new org.apache.tools.ant.Project()
    
    antProject.setBaseDir(new File("${project.projectDir}"))
    gatheringTask.setProject(antProject)
    gatheringTask.setVersion("version")
    gatheringTask.setRevision("revision")
    
    gatheringTask.setClean("clean")
    
        gatheringTask.execute()
        versionNumber = antProject.getProperty("version")
        revisionNumber = antProject.getProperty("revision")
        cleanFlag = antProject.getProperty("clean")
        
        // set version
        version=versionNumber+"-r"+revisionNumber
        println "${project.name}: ${version}"
        
        // create BUILD INFO file
        def targetsDist = 'targets/dist'
        def distFolder = new File("${project.projectDir}/${targetsDist}")
        distFolder.deleteDir()
        distFolder.mkdirs()
        
        def writer = new FileWriter("${project.projectDir}/${targetsDist}/BUILD-${project.name}.INFO")
        try {
            writer.println("${versionNumber}:${revisionNumber}:${cleanFlag}")
        } finally {
            writer.close()
        }
    } catch (Exception e) {
    	println "skipping gathering"
    
    task checkRestrictions(type: Exec, dependsOn: [classes, testClasses]) {
        doFirst {
            cp = configurations.testCompile.filter({ f -> f.name.startsWith('restrictionchecker') || f.name.startsWith('bcel')}).asPath
    
            cmd = ['java', '-cp', cp, 'ch.rinn.restrictions.RestrictionChecker', '-r', sourceSets.main.output.classesDir]
            if (sourceSets.test.output.classesDir.exists()) {
                cmd.add(sourceSets.test.output.classesDir)
            }
            cmd.add('-cp')
            cmd.add(sourceSets.main.output.classesDir)
            if (sourceSets.test.output.classesDir.exists()) {
                cmd.add(sourceSets.test.output.classesDir)
            }
            cmd.add(configurations.testCompile.asPath)
            commandLine cmd
    
        useTestNG()
        options.suites('sourceTest/java/tests.xml')    
    
        jvmArgs '-Xmx2048m', '-XX:MaxPermSize=256m', '-Duser.timezone=Europe/Zurich'
    
        
        testLogging.showStandardStreams = true
    
        ignoreFailures = true
    
        options.encoding = 'utf-8'
        options.fork = true
        doFirst {
            options.forkOptions.with {
                executable = 'java'
    
                if (addSource) {
    	            jvmArgs = ['-cp', configurations.ecj.asPath, 'org.eclipse.jdt.internal.compiler.batch.Main', 
    	                       '-nowarn', '-source', '1.6']
    	        } else {
    	            jvmArgs = ['-cp', configurations.ecj.asPath, 'org.eclipse.jdt.internal.compiler.batch.Main', 
    	                       '-nowarn']
    	        }
    
        options.encoding = 'utf-8'
        options.fork = true
        doFirst {
            options.forkOptions.with {
                executable = 'java'
    
                if (addSource) {
    	            jvmArgs = ['-cp', configurations.ecj.asPath, 'org.eclipse.jdt.internal.compiler.batch.Main', 
    	                       '-nowarn', '-source', '1.6']
    	        } else {
    	            jvmArgs = ['-cp', configurations.ecj.asPath, 'org.eclipse.jdt.internal.compiler.batch.Main', 
    	                       '-nowarn']
    	        }
    
    processTestResources {
    
        fileMode=0666
    
    apply plugin: 'eclipse'
    
    eclipse {
    
        classpath {
            downloadSources=true
            defaultOutputDir = file('targets')
        }
    
        whenMerged{ classpath ->
            def projectRefs = classpath.entries.findAll{entry -> entry.kind =='src' && entry.path.startsWith('/')}
            classpath.entries.removeAll(projectRefs)
            classpath.entries.addAll(projectRefs)   
        }   
    
    }
    
    task testJar(type: Jar, dependsOn: testClasses) {
        baseName = "test-${project.archivesBaseName}"
        from sourceSets.test.output
    }
    
    
    task sourcesJar(type: Jar) {
    
        from sourceSets.main.allSource
    
    task sourceJarForEclipseLaunchConfigs(type: Copy, dependsOn: sourcesJar) {
    
    	into sourcesJar.destinationDir
    	from sourcesJar.archivePath
    	rename '.*', 'sources.jar'
    
    compileJava.dependsOn sourceJarForEclipseLaunchConfigs
    
    }
    
    task compileDependencies(type: Copy) {
        into "$buildDir/output/compile-dependencies"
        from configurations.compile
    }
    
    task runtimeDependencies(type: Copy) {
        into "$buildDir/output/runtime-dependencies"
        from configurations.runtime
    }
    
    task testCompileDependencies(type: Copy) {
        into "$buildDir/output/testCompile-dependencies"
        from configurations.testCompile
    }
    
    task testRuntimeDependencies(type: Copy) {
        into "$buildDir/output/testRuntime-dependencies"
        from configurations.testRuntime
    
    }
    
    task checkDependencies(dependsOn: classes) << {
    	ant.taskdef(name: 'dependencychecker', classname: 'classycle.ant.DependencyCheckingTask', classpath: configurations.testRuntime.asPath)
        ant.dependencychecker(
    
                    definitionFile: 'resource/dependency-structure.ddf', 
                    failOnUnwantedDependencies: 'true',
                    mergeInnerClasses: 'true') {
            fileset(dir: "${buildDir}", includes: "**/*.class")
        }
    }
    
    apply plugin: 'ivy-publish'
    publishing {
        publications {
            ivy(IvyPublication) {
                from components.java
                artifact(sourcesJar)
            }
        }
        repositories {
            ivy {
                ivyPattern "file://${project.projectDir}/../ivy-repository/[organisation]/[module]/[revision]/ivy.xml"
                artifactPattern "file://${project.projectDir}/../ivy-repository/[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]"
            }
        }
    }
    
    publish {
        dependsOn build