-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
153 lines (123 loc) · 4.73 KB
/
build.gradle
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
plugins {
id 'com.gradle.plugin-publish' version '1.1.0'
id "maven-publish"
id 'java'
id 'idea'
}
def currentBranch = ("git rev-parse --abbrev-ref HEAD").execute().inputStream.readLines().get(0)
if (currentBranch != "master") {
version = project.version + "-dev"
} else {
version = project.version
}
group = project.group
repositories {
mavenCentral()
}
//using java 8 for compatibility with old projects
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
dependencies {
implementation gradleApi()
implementation 'org.jetbrains:annotations:24.0.1'
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.13.1.202206130422-r'
implementation 'com.google.code.gson:gson:2.10.1'
//implementation 'com.google.guava:guava:31.1-jre'
//enables java 17 features on java 8
String jabelPlugin = 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0'
compileOnly 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0'
annotationProcessor jabelPlugin
testAnnotationProcessor jabelPlugin
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'
}
configure([tasks.compileJava, tasks.compileTestJava]) {
sourceCompatibility = 17 // for the IDE support
options.release = 8
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(17)
}
}
configure([tasks.javadoc]) {
javadocTool.set(javaToolchains.javadocToolFor {
languageVersion = JavaLanguageVersion.of(17)
})
}
tasks.named('test') {
useJUnitPlatform()
}
gradlePlugin {
website = "https://github.com/Srdjan-V/LocalGitDependency"
vcsUrl = "https://github.com/Srdjan-V/LocalGitDependency"
plugins {
localGitDependency {
displayName = "Local Git Dependency Plugin"
description = "Gradle plugin to clone projects with git and build them"
tags.set(["java", "git", "dependency"])
id = "io.github.srdjan-v.local-git-dependency"
implementationClass = "io.github.srdjanv.localgitdependency.LocalGitDependencyPlugin"
}
modelInjection {
displayName = "Local Git Dependency Model Injection Plugin"
description = "Helper plugin for local git dependency"
tags.set(["model", "java", "git", "dependency"])
id = "io.github.srdjan-v.model-injection"
implementationClass = "io.github.srdjanv.localgitdependency.injection.plugin.ModelInjectionPlugin"
}
}
}
import org.apache.tools.ant.filters.ReplaceTokens
task filterTokens(type: Sync) {
inputs.property 'version', version
from sourceSets.main.java
filter(ReplaceTokens, tokens: [PLUGIN_VERSION: version.toString()])
into "$buildDir/src/$sourceSets.main.name/$sourceSets.main.java.name"
}
compileJava.source = filterTokens.outputs
publishing {
publications {
pluginMaven(MavenPublication) {
artifactId = 'local-git-dependency'
}
}
}
def publishPluginsChecks = tasks.register("publishPluginsChecks") {
doLast {
if (currentBranch != "master") {
throw new RuntimeException("You can't publish to the gradle plugin portal if not on the master branch")
}
def projectVersion = project.version.toString().split("\\.")
if (projectVersion.length != 3) {
throw new RuntimeException("The project version must be composed of 3 numbers")
}
def versionTagArray = new ArrayList<Integer>()
for (final def versionString in projectVersion) {
try {
versionTagArray.add(Integer.valueOf(versionString))
} catch (NumberFormatException e) {
throw new RuntimeException("Inappropriate character in project version string", e)
}
}
def gitVersionTagArray = new ArrayList<Integer>()
def gitStringTag = ("git describe --tags --abbrev=0").execute().inputStream.readLines().get(0)
for (versionString in gitStringTag.substring(1, gitStringTag.length()).trim().split("\\.")) {
gitVersionTagArray.add(Integer.valueOf(versionString))
}
def invalid = true
def iterator = 0
for (final def versionString in projectVersion) {
if (versionTagArray.get(iterator) > gitVersionTagArray.get(iterator)) {
invalid = false
break
}
iterator++
}
if (invalid) {
throw new RuntimeException("Current project version is the same or lower then the latest tag")
}
project.logger.lifecycle('Pushing tag {}', project.version)
("git tag v${project.version}").execute()
("git push --tags").execute()
}
}
tasks.getByName("publishPlugins").configure {
dependsOn publishPluginsChecks
}