summaryrefslogtreecommitdiff
path: root/build.gradle
blob: 92f9609fbf59828cc5c5d733ac9a37feb2d72a39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
buildscript {
    dependencies {
        classpath "org.mini2Dx:parcl:1.7.1"
    }
}

plugins {
  id 'java'
  id 'maven-publish'
  id 'com.github.johnrengelman.shadow' version '5.1.0'
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
apply plugin: "org.mini2Dx.parcl"

repositories {
    flatDir {
       dirs 'lib'
    }
    mavenCentral()
}

sourceSets {
    main {
        java {
	    srcDirs = ['source']
        }
    }

    test {
        java {
            srcDirs = ['test/java']
        }
    }
}

group = 'net.yacy'
version = '1.925'
description = 'YaCy Search Server'
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8

mainClassName = "net.yacy.yacy"
applicationDefaultJvmArgs = ["-Xmx1024m"]

// create property store for filterTokens (here, to make sure it exist)
project.ext.filterTokens = new Properties()

parcl {
   exe {
      exeName = "YaCy"
   }

   app {
      vmArgs = ["-Xmx1g"]
      appName = "YaCy"
      icon = "addon/YaCy.icns"
      applicationCategory = "Search-Engine"
      displayName = 'YaCy Search Engine'
      identifier = 'net.yacy'
      copyright = 'Copyright 2021 Michael Peter Christen et al.'
      zipName = 'YaCy.zip'
   }

   linux {
      binName = "YaCy"
   }
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

dependencies {
    implementation(fileTree(dir : "lib", include : "*.jar"))

    // need at least one entry to make references to configuragtion.xxxx work in combination with local lib directory
    implementation 'org.apache.james:apache-mime4j:0.6'
    implementation 'org.apache.calcite.avatica:avatica-core:1.13.0'
    implementation 'org.bouncycastle:bcmail-jdk15on:1.69'
    implementation 'commons-codec:commons-codec:1.14'
    implementation 'com.ibm.icu:icu4j:63.1'

    testImplementation('junit:junit:4.13.2')
}

// output to lib/yacycore.jar (like with ant with downside by determine class-path)
jar {
    archiveFileName = 'yacycore.jar'
    destinationDirectory  = new File('lib')
    manifest {
        attributes(
            "Main-Class": mainClassName ,
            "Class-Path": configurations.compileClasspath.collect { it.name }.join(' ')               
        )
    }
}

shadowJar.zip64 = true // saw build error: Execution failed for task ':shadowJar'. shadow.org.apache.tools.zip.Zip64RequiredException: archive contains more than 65535 entries.

// mimic current config with dependencies in lib directory
// @TODO: maybe removed after complete Gradle migration
task copyDependenciesToLib(type: Copy) {
    def destination = project.file("lib")
    into destination
    from configurations.compileClasspath
    eachFile { // prevent overwriting existing files
        if (it.getRelativePath().getFile(destination).exists()) {
            it.exclude()
        }
    }
    build.dependsOn(copyDependenciesToLib)
}
    
// runs the support tool which creates gitbuildnumber.properties from info of local git repository
task runGitComInf(type: JavaExec) {
    classpath = files('libbuild/GitComInf-all.jar')
    args = [project.projectDir.getPath(), project.projectDir.getPath() + "/build/tmp/gitbuildnumber.properties"]
    mainClass = 'GitComInf'
}

// prepare yacyBuildProperties.java from template (needed after commits or new versions)
// read values from property file generated by GitComInf tool
import org.apache.tools.ant.filters.ReplaceTokens
task prepYaCyProperties (type: Copy) {
    mustRunAfter runGitComInf
    def propfile = "build/tmp/gitbuildnumber.properties";
    if (project.file(propfile).exists()) { // must check otherwise any action may stop after clean on this error
        file("build/tmp/gitbuildnumber.properties").withReader { 
            Properties props = new Properties()
            props.load(it)
            project.ext.filterTokens.putAll(props)
        }
    } else 
        logger.error("prepYaCyProperties: file " + propfile + " is missing, you should re-run runGitComInf")
    
    String fdirname = sourceSets.main.java.srcDirs[0].name + '/net/yacy/peers/operation'
    copy {
        from fdirname
        include('yacyBuildProperties.java.template')
        rename 'yacyBuildProperties.java.template', 'yacyBuildProperties.java'
        into (fdirname)

        filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: project.ext.filterTokens)
        filter(ReplaceTokens, tokens: [REPL_VERSION: version, REPL_PKGMANAGER:"false", REPL_RESTARTCMD: "/etc/init.d/yacy restart"]) // gradle.project.version + some defaults from ant
    }
}
prepYaCyProperties.dependsOn(runGitComInf)
compileJava.dependsOn(prepYaCyProperties) // must be executed before compile

/** -----------------------------------------------------------
 * Settings during the migration from Ant to Gradle build
 * importing Ant targets and to use them within this Gradle build
 * until/where functionality has not been migrated yet
 * ------------------------------------------------------------
 */
// Import Ant build and prefix all task names with 'ant_' to prevent naming conflict with Gradle tasks.
ant.importBuild('build.xml') { antTaskName -> "ant_${antTaskName}".toString() }

// Set group property for all Ant tasks.
tasks.matching { task -> task.name.startsWith('ant_') }*.group = 'Ant'

// include compile of htroot servlets in Gradle lifecycle somewhere after compileJava
startScripts.dependsOn("ant_gradle-compile-htroot")