Archived
0
This repository has been archived on 2022-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
mc-server/build.gradle

169 lines
5.5 KiB
Groovy

import java.nio.file.Files
import java.nio.file.Paths
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath (group: 'org.sonarsource.scanner.gradle', name: 'sonarqube-gradle-plugin', version: '2.6.2')
}
}
/**
* Проверка кода в SonarQube.
* Для запуска локальной проверки кода, используются следующий command line:
* gradle sonarqube \
* -Dsonar.host.url=http://127.0.0.1:9000
* -Dsonar.login=<TOKEN>
* где
* - <TOKEN> - сгенерированный токен учетки "сонара"
*/
plugins {
id "org.sonarqube" version "2.6.2"
}
allprojects {
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/groups/public/' }
}
}
subprojects {
apply plugin: 'java'
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
options.encoding = 'UTF-8'
}
group 'mc'
ext {
slf4j_version = '1.7.25'
spring_version = '5.1.0.RELEASE'
lombok_version = '1.18.4'
junit_version = '5.3.1'
}
configurations {
compile_excludeCopy
compile.extendsFrom compile_excludeCopy
}
dependencies {
compile (group: 'org.jetbrains', name: 'annotations', version: '16.0.3')
/* Logger */
compile (group: 'org.slf4j', name: 'slf4j-api', version: slf4j_version)
compile (group: 'org.slf4j', name: 'jcl-over-slf4j', version: slf4j_version)
/* Spring */
compile (group: 'org.springframework', name: 'spring-context', version: spring_version)
/* Lombok */
annotationProcessor (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
compile (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
testAnnotationProcessor (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
testCompile (group: 'org.projectlombok', name: 'lombok', version: lombok_version)
/* Testing */
testImplementation (group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junit_version)
testRuntimeOnly(group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit_version)
testImplementation(group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junit_version)
testCompile (group: 'org.slf4j', name: 'slf4j-simple', version: slf4j_version)
testCompile (group: 'org.mockito', name: 'mockito-core', version: '1.10.19')
testCompile (group: 'org.springframework', name: 'spring-test', version: spring_version)
}
test {
useJUnitPlatform()
}
task copyDep(type: Copy) {
into 'libs'
from configurations.compile + configurations.runtime - configurations.compile_excludeCopy
}
task cleanDep(type: Delete) {
delete 'libs'
}
/**
* Сборка
*/
task deploy() {
dependsOn { jar }
doLast {
def deployDir = System.getProperty("deploy")
if (deployDir == null) {
println "Need param -Ddeploy=path/to/deploy"
throw new Exception("Need param -Ddir=path/to/deploy")
}
def target = Paths.get(deployDir, jar.archivePath.getName())
if (Files.notExists(target)) {
println jar.archivePath
Files.copy(jar.archivePath.toPath(), target)
}
def libsDir = System.getProperty("libs", deployDir + File.separator + "libs")
if (Files.notExists(Paths.get(libsDir))) {
(new File(libsDir)).mkdirs()
}
def libsCollection = configurations.compile + configurations.runtime - configurations.compile_excludeCopy
libsCollection.each{ libFile ->
target = Paths.get(libsDir, libFile.getName())
if (Files.notExists(target)) {
println libFile
Files.copy(libFile.toPath(), target)
}
}
if (Boolean.valueOf(System.getProperty("createRunScript", "false"))) {
def runnerSh = new File(deployDir, "run.sh")
runnerSh.write "java -cp \"${project(':core').jar.archiveName};"
runnerSh << "${libsDir}/*;./log-impl/*\" mc.core.Main\n"
}
}
}
}
/**
* Запуск сервера.
* Для указания рабочей папки, указываем JVM параметр
* -DworkDir=path\to\workdir
* Если используется отдельная папка для имплементации логгера, то указываем
* -DlogImplDir=path\to\logimpldir
*/
task runServer(type: JavaExec) {
main = 'mc.core.Main'
workingDir = System.getProperty("workDir", ".")
subprojects.findAll().each{ prj ->
classpath += prj.sourceSets.main.runtimeClasspath
}
if (System.getProperty("logImplDir") != null) {
def logImplDir = new File(System.getProperty("logImplDir"))
if (logImplDir.isAbsolute()) {
classpath += files(fileTree(dir: logImplDir))
} else {
classpath += files(fileTree(dir: new File(workingDir, logImplDir.getPath())))
}
} else {
classpath += files(fileTree(dir: new File(workingDir, "log-impl")))
}
systemProperties System.properties
systemProperties.put("user.dir", workingDir)
ignoreExitValue = true
}