Skip to content

Commit d07f695

Browse files
authored
Add utbot-gradle publishing to the build file (#363)
1 parent 0fb3fc3 commit d07f695

File tree

2 files changed

+148
-147
lines changed

2 files changed

+148
-147
lines changed

utbot-gradle/build.gradle

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,79 @@
11
plugins {
22
id 'java-gradle-plugin'
3+
id 'com.gradle.plugin-publish' version '0.18.0'
4+
id 'com.github.johnrengelman.shadow' version '6.1.0'
35
}
46

57
apply from: "${parent.projectDir}/gradle/include/jvm-project.gradle"
68

79
dependencies {
8-
api project(":utbot-framework")
10+
shadow gradleApi()
11+
shadow localGroovy()
12+
13+
implementation project(":utbot-framework")
914

1015
implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlin_logging_version
1116
}
1217

18+
// needed to prevent inclusion of gradle-api into shadow JAR
19+
configurations.compile.dependencies.remove dependencies.gradleApi()
20+
1321
configurations.all {
1422
exclude group: "org.apache.logging.log4j", module: "log4j-slf4j-impl"
1523
}
1624

17-
gradlePlugin {
18-
plugins {
19-
sarifReportPlugin {
20-
id = 'org.utbot.gradle.plugin'
21-
implementationClass = 'org.utbot.gradle.plugin.SarifGradlePlugin'
22-
}
25+
jar {
26+
manifest {
27+
// 'Fat JAR' is needed in org.utbot.framework.codegen.model.util.DependencyUtilsKt.checkDependencyIsFatJar
28+
attributes 'JAR-Type': 'Fat JAR'
29+
attributes 'Class-Path': configurations.compile.collect { it.getName() }.join(' ')
2330
}
2431
}
2532

33+
shadowJar {
34+
archiveClassifier.set('')
35+
minimize()
36+
}
37+
38+
// no module metadata => no dependency on the `utbot-framework`
39+
tasks.withType(GenerateModuleMetadata) {
40+
enabled = false
41+
}
42+
2643
publishing {
44+
publications {
45+
pluginMaven(MavenPublication) {
46+
pom.withXml {
47+
// removing a dependency to `utbot-framework` from the list of dependencies
48+
asNode().dependencies.dependency.each { dependency ->
49+
if (dependency.artifactId[0].value()[0] == 'utbot-framework') {
50+
assert dependency.parent().remove(dependency)
51+
}
52+
}
53+
}
54+
}
55+
}
2756
repositories {
2857
maven {
2958
url = layout.buildDirectory.dir('repo')
3059
}
3160
}
3261
}
62+
63+
pluginBundle {
64+
website = 'https://www.utbot.org/'
65+
vcsUrl = 'https://github.com/UnitTestBot/UTBotJava/'
66+
tags = ['java', 'unit-testing', 'tests-generation', 'sarif']
67+
}
68+
69+
gradlePlugin {
70+
plugins {
71+
sarifReportPlugin {
72+
version = '1.0.0-alpha-9' // last published version
73+
id = 'org.utbot.gradle.plugin'
74+
displayName = 'UnitTestBot gradle plugin'
75+
description = 'The gradle plugin for generating tests and creating SARIF reports based on UnitTestBot'
76+
implementationClass = 'org.utbot.gradle.plugin.SarifGradlePlugin'
77+
}
78+
}
79+
}

utbot-gradle/docs/utbot-gradle.md

Lines changed: 94 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@ In addition, it creates one big SARIF-report containing the results from all the
88

99
### How to use
1010

11-
_TODO: The plugin has not been published yet._
11+
Please, check for the available versions [here](https://plugins.gradle.org/plugin/org.utbot.gradle.plugin).
1212

1313
- Apply the plugin:
14-
15-
<details>
16-
<summary>Groovy</summary>
17-
<pre>
18-
apply plugin: 'org.utbot.gradle.plugin'
19-
</pre>
20-
</details>
2114

22-
<details>
23-
<summary>Kotlin DSL</summary>
24-
<pre>
25-
apply(plugin = "org.utbot.gradle.plugin")
26-
</pre>
27-
</details>
15+
__Groovy:__
16+
```Groovy
17+
plugins {
18+
id "org.utbot.gradle.plugin" version "..."
19+
}
20+
```
21+
__Kotlin DSL:__
22+
```Kotlin
23+
plugins {
24+
id("org.utbot.gradle.plugin") version "..."
25+
}
26+
```
2827

2928
- Run gradle task `utbot/generateTestsAndSarifReport` to create a report.
3029

@@ -33,48 +32,42 @@ _TODO: The plugin has not been published yet._
3332

3433
For example, the following configuration may be used:
3534

36-
<details>
37-
<summary>Groovy</summary>
38-
<pre>
39-
sarifReport {
40-
targetClasses = ['com.abc.Main', 'com.qwerty.Util']
41-
projectRoot = 'C:/.../SomeDirectory'
42-
generatedTestsRelativeRoot = 'build/generated/test'
43-
sarifReportsRelativeRoot = 'build/generated/sarif'
44-
markGeneratedTestsDirectoryAsTestSourcesRoot = true
45-
testFramework = 'junit5'
46-
mockFramework = 'mockito'
47-
generationTimeout = 60000L
48-
codegenLanguage = 'java'
49-
mockStrategy = 'package-based'
50-
staticsMocking = 'mock-statics'
51-
forceStaticMocking = 'force'
52-
classesToMockAlways = ['org.slf4j.Logger', 'java.util.Random']
53-
}
54-
</pre>
55-
</details>
56-
57-
58-
<details>
59-
<summary>Kotlin DSL</summary>
60-
<pre>
61-
configure&lt;SarifGradleExtension&gt; {
62-
targetClasses.set(listOf("com.abc.Main", "com.qwerty.Util"))
63-
projectRoot.set("C:/.../SomeDirectory")
64-
generatedTestsRelativeRoot.set("build/generated/test")
65-
sarifReportsRelativeRoot.set("build/generated/sarif")
66-
markGeneratedTestsDirectoryAsTestSourcesRoot.set(true)
67-
testFramework.set("junit5")
68-
mockFramework.set("mockito")
69-
generationTimeout.set(60000L)
70-
codegenLanguage.set("java")
71-
mockStrategy.set("package-based")
72-
staticsMocking.set("mock-statics")
73-
forceStaticMocking.set("force")
74-
classesToMockAlways.set(listOf("org.slf4j.Logger", "java.util.Random"))
75-
}
76-
</pre>
77-
</details>
35+
__Groovy:__
36+
```Groovy
37+
sarifReport {
38+
targetClasses = ['com.abc.Main', 'com.qwerty.Util']
39+
projectRoot = 'C:/.../SomeDirectory'
40+
generatedTestsRelativeRoot = 'build/generated/test'
41+
sarifReportsRelativeRoot = 'build/generated/sarif'
42+
markGeneratedTestsDirectoryAsTestSourcesRoot = true
43+
testFramework = 'junit5'
44+
mockFramework = 'mockito'
45+
generationTimeout = 60000L
46+
codegenLanguage = 'java'
47+
mockStrategy = 'package-based'
48+
staticsMocking = 'mock-statics'
49+
forceStaticMocking = 'force'
50+
classesToMockAlways = ['org.slf4j.Logger', 'java.util.Random']
51+
}
52+
```
53+
__Kotlin DSL:__
54+
```Kotlin
55+
configure<SarifGradleExtension> {
56+
targetClasses.set(listOf("com.abc.Main", "com.qwerty.Util"))
57+
projectRoot.set("C:/.../SomeDirectory")
58+
generatedTestsRelativeRoot.set("build/generated/test")
59+
sarifReportsRelativeRoot.set("build/generated/sarif")
60+
markGeneratedTestsDirectoryAsTestSourcesRoot.set(true)
61+
testFramework.set("junit5")
62+
mockFramework.set("mockito")
63+
generationTimeout.set(60000L)
64+
codegenLanguage.set("java")
65+
mockStrategy.set("package-based")
66+
staticsMocking.set("mock-statics")
67+
forceStaticMocking.set("force")
68+
classesToMockAlways.set(listOf("org.slf4j.Logger", "java.util.Random"))
69+
}
70+
```
7871

7972
**Note:** All configuration fields have default values, so there is no need to configure the plugin if you don't want to.
8073

@@ -151,94 +144,45 @@ configure&lt;SarifGradleExtension&gt; {
151144

152145
If you want to change the source code of the plugin or even the whole utbot-project,
153146
you need to do the following:
154-
- Publish the modified project to the local maven repository
155-
- Correctly specify the dependencies in the build file (in your project)
156-
- Apply the plugin (see the section __How to use__).
157-
158-
There are two ways to do it.
159-
160-
- **The first way**
161-
- Run `publishing/publishToMavenLocal` (**utbot root** gradle task)
162-
163-
- Add to your build file:
164-
165-
<details>
166-
<summary>Groovy</summary>
167-
<pre>
168-
buildscript {
169-
repositories {
170-
mavenLocal()
171-
mavenCentral()
172-
maven { url 'https://jitpack.io' }
173-
}
174-
&nbsp;
175-
dependencies {
176-
classpath group: 'org.utbot', name: 'utbot-gradle', version: '1.0-SNAPSHOT'
177-
}
147+
148+
- Publish plugin to the local maven repository:
149+
`utbot-gradle/publishing/publishToMavenLocal`
150+
151+
- Add to your build file:
152+
153+
__Groovy:__
154+
```Groovy
155+
buildscript {
156+
repositories {
157+
mavenLocal()
178158
}
179-
</pre>
180-
</details>
181-
182-
<details>
183-
<summary>Kotlin DSL</summary>
184-
<pre>
185-
buildscript {
186-
repositories {
187-
mavenLocal()
188-
mavenCentral()
189-
maven { url 'https://jitpack.io' }
190-
}
191-
&nbsp;
192-
dependencies {
193-
classpath("org.utbot:utbot-gradle:1.0-SNAPSHOT")
194-
}
159+
dependencies {
160+
classpath "org.utbot:utbot-gradle:1.0-SNAPSHOT"
195161
}
196-
</pre>
197-
</details>
198-
199-
- **The second way** (faster, but more difficult)
200-
- Run `publishing/publishToMavenLocal` (**utbot-gradle** gradle task)
201-
- Add to your `build.gradle`:
202-
203-
<details>
204-
<summary>Groovy</summary>
205-
<pre>
206-
buildscript {
207-
repositories {
208-
mavenLocal()
209-
mavenCentral()
210-
maven { url 'https://jitpack.io' }
211-
}
212-
&nbsp;
213-
dependencies {
214-
classpath group: 'org.utbot', name: 'utbot-gradle', version: '1.0-SNAPSHOT'
215-
classpath files('C:/..[your-path]../UTBotJava/utbot-framework/build/libs/utbot-framework-1.0-SNAPSHOT.jar')
216-
classpath files('C:/..[your-path]../UTBotJava/utbot-framework-api/build/libs/utbot-framework-api-1.0-SNAPSHOT.jar')
217-
classpath files('C:/..[your-path]../UTBotJava/utbot-instrumentation/build/libs/utbot-instrumentation-1.0-SNAPSHOT.jar')
218-
}
162+
}
163+
```
164+
__Kotlin DSL:__
165+
```Kotlin
166+
buildscript {
167+
repositories {
168+
mavenLocal()
219169
}
220-
</pre>
221-
</details>
222-
223-
<details>
224-
<summary>Kotlin DSL</summary>
225-
<pre>
226-
buildscript {
227-
repositories {
228-
mavenLocal()
229-
mavenCentral()
230-
maven { url 'https://jitpack.io' }
231-
}
232-
&nbsp;
233-
dependencies {
234-
classpath("org.utbot:utbot-gradle:1.0-SNAPSHOT")
235-
classpath(files("C:/..[your-path]../UTBotJava/utbot-framework/build/libs/utbot-framework-1.0-SNAPSHOT.jar"))
236-
classpath(files("C:/..[your-path]../UTBotJava/utbot-framework-api/build/libs/utbot-framework-api-1.0-SNAPSHOT.jar"))
237-
classpath(files("C:/..[your-path]../UTBotJava/utbot-instrumentation/build/libs/utbot-instrumentation-1.0-SNAPSHOT.jar"))
238-
}
170+
dependencies {
171+
classpath("org.utbot:utbot-gradle:1.0-SNAPSHOT")
239172
}
240-
</pre>
241-
</details>
173+
}
174+
```
175+
176+
- Apply the plugin:
177+
178+
__Groovy:__
179+
```Groovy
180+
apply plugin: 'org.utbot.gradle.plugin'
181+
```
182+
__Kotlin DSL:__
183+
```Kotlin
184+
apply(plugin = "org.utbot.gradle.plugin")
185+
```
242186

243187
### How to configure the log level
244188

@@ -252,6 +196,16 @@ Also note that the standard way to configure the log level (using the `log4j2.xm
252196

253197
[Read more about gradle log levels](https://docs.gradle.org/current/userguide/logging.html)
254198

199+
### Publishing
200+
201+
1. Read the [documentation](https://docs.gradle.org/current/userguide/publishing_gradle_plugins.html) about plugin publishing
202+
2. Sign in to our [account](https://plugins.gradle.org/u/utbot) to get API keys (if you don't have a password, please contact [Nikita Stroganov](https://github.com/IdeaSeeker))
203+
3. Run `utbot-gradle/plugin portal/publishPlugins` gradle task
204+
205+
You can check the published artifacts in the [remote repository](https://plugins.gradle.org/m2/org/utbot/utbot-gradle/).
206+
207+
Please note that the maximum archive size for publishing on the Gradle Plugin Portal is ~60Mb.
208+
255209
### Requirements
256210

257211
UTBot gradle plugin requires Gradle 6.8+

0 commit comments

Comments
 (0)