Skip to content

Commit a630e80

Browse files
committed
add NebulaLibraryPlugin and root plugin to help publish plain libraries for the Nebula ecosystem and support multi-project repos
1 parent d2cd89e commit a630e80

5 files changed

Lines changed: 259 additions & 29 deletions

File tree

README.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,27 @@ To apply this plugin
2626
id 'nebula.plugin-plugin' version '<current version>'
2727
}
2828

29-
30-
Gradle Compatibility Tested
31-
---------------------------
3229

33-
* Built with Oracle JDK8
34-
* Tested with Oracle JDK8
35-
36-
| Gradle Version | Works |
37-
| :------------: | :---: |
38-
| < 4.5 . | no |
39-
| 4.5 > | yes |
30+
### Multi-project Repo
31+
32+
To use this plugin in a multiproject repo, apply this root plugin to the root project:
33+
```kotlin
34+
plugins {
35+
id("com.netflix.nebula.root")
36+
}
37+
```
38+
Then, in each subproject, if it is a plugin project, apply the plugin plugin:
39+
```kotlin
40+
plugins {
41+
id("com.netflix.nebula.plugin-plugin")
42+
}
43+
```
44+
Otherwise, if it is a plain Java library project, apply the library plugin:
45+
```kotlin
46+
plugins {
47+
id("com.netflix.nebula.library")
48+
}
49+
```
4050

4151
LICENSE
4252
=======

build.gradle.kts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
*/
1616
plugins {
1717
id("com.netflix.nebula.plugin-plugin") version "23.+"
18+
`kotlin-dsl`
1819
}
1920

2021
description = "Project plugin for Nebula plugins"
2122

2223
contacts {
23-
// addPerson("nebula-plugins-oss@netflix.com") {
24-
// moniker = "Nebula Plugins Maintainers"
25-
// github = "nebula-plugins"
26-
// }
24+
addPerson("nebula-plugins-oss@netflix.com") {
25+
moniker = "Nebula Plugins Maintainers"
26+
github = "nebula-plugins"
27+
}
2728
}
2829

2930
repositories {
@@ -42,7 +43,7 @@ dependencies {
4243
implementation ("com.netflix.nebula:nebula-project-plugin:latest.release")
4344
implementation ("com.netflix.nebula:nebula-release-plugin:latest.release")
4445
implementation ("com.netflix.nebula:nebula-gradle-interop:latest.release")
45-
46+
implementation("com.netflix.nebula:gradle-info-plugin:latest.release")
4647
implementation (platform("com.fasterxml.jackson:jackson-bom:2.14.+"))
4748

4849
implementation ("com.gradle.publish:plugin-publish-plugin:1.3.1")
@@ -62,14 +63,21 @@ gradlePlugin {
6263
displayName = "Nebula Plugin Plugin"
6364
description = "Sets up publishing and release process for all of the other nebula plugins"
6465
implementationClass = "nebula.plugin.plugin.NebulaPluginPlugin"
65-
// tags.set(["nebula", "nebula-plugin"])
66+
tags.set(listOf("nebula", "nebula-plugin"))
6667
}
6768
create("libraryPlugin") {
68-
id = "com.netflix.nebula.library-plugin"
69+
id = "com.netflix.nebula.library"
6970
displayName = "Nebula Library Plugin"
7071
description = "Sets up publishing and release process for Nebula Libraries"
7172
implementationClass = "nebula.plugin.plugin.NebulaLibraryPlugin"
72-
// tags.set(["nebula"])
73+
tags.set(listOf("nebula"))
74+
}
75+
create("rootPlugin") {
76+
id = "com.netflix.nebula.root"
77+
displayName = "Nebula Root Plugin"
78+
description = "Sets up publishing and release process for Nebula Multiproject Repos"
79+
implementationClass = "nebula.plugin.plugin.NebulaRootPlugin"
80+
tags.set(listOf("nebula"))
7381
}
7482
}
7583
}
@@ -79,3 +87,10 @@ java {
7987
languageVersion.set(JavaLanguageVersion.of(17))
8088
}
8189
}
90+
testing {
91+
suites {
92+
named<JvmTestSuite>("test"){
93+
useJUnitJupiter()
94+
}
95+
}
96+
}

gradle.lockfile

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ com.netflix.nebula:nebula-oss-publishing-plugin:3.6.0=compileClasspath,integTest
1717
com.netflix.nebula:nebula-project-plugin:12.0.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1818
com.netflix.nebula:nebula-publishing-plugin:22.0.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1919
com.netflix.nebula:nebula-release-plugin:21.0.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
20-
com.netflix.nebula:nebula-test:11.0.0=testCompileClasspath,testRuntimeClasspath
21-
com.netflix.nebula:nebula-test:11.6.3=integTestCompileClasspath,integTestRuntimeClasspath
20+
com.netflix.nebula:nebula-test:11.6.3=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
2221
com.perforce:p4java:2015.2.1365273=integTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
2322
com.squareup.moshi:moshi:1.12.0=integTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
2423
com.squareup.okio:okio:2.10.0=integTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
@@ -38,18 +37,20 @@ org.codehaus.plexus:plexus-utils:3.2.1=integTestRuntimeClasspath,runtimeClasspat
3837
org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
3938
org.hamcrest:hamcrest-core:1.3=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
4039
org.hamcrest:hamcrest:2.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
40+
org.jetbrains.kotlin:kotlin-reflect:2.2.0=compileClasspath,embeddedKotlin,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
4141
org.jetbrains.kotlin:kotlin-stdlib-common:1.4.20=integTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
4242
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
4343
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
44-
org.jetbrains.kotlin:kotlin-stdlib:2.2.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
45-
org.jetbrains:annotations:13.0=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
46-
org.jspecify:jspecify:1.0.0=integTestCompileClasspath,integTestRuntimeClasspath
47-
org.junit.platform:junit-platform-commons:1.13.1=testCompileClasspath,testRuntimeClasspath
48-
org.junit.platform:junit-platform-commons:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath
49-
org.junit.platform:junit-platform-engine:1.13.1=testCompileClasspath,testRuntimeClasspath
50-
org.junit.platform:junit-platform-engine:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath
51-
org.junit.platform:junit-platform-launcher:1.13.1=testCompileClasspath,testRuntimeClasspath
52-
org.junit.platform:junit-platform-launcher:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath
44+
org.jetbrains.kotlin:kotlin-stdlib:2.2.0=compileClasspath,embeddedKotlin,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
45+
org.jetbrains:annotations:13.0=compileClasspath,embeddedKotlin,integTestCompileClasspath,integTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
46+
org.jspecify:jspecify:1.0.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
47+
org.junit.jupiter:junit-jupiter-api:5.12.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
48+
org.junit.jupiter:junit-jupiter-engine:5.12.2=integTestRuntimeClasspath,testRuntimeClasspath
49+
org.junit.jupiter:junit-jupiter-params:5.12.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
50+
org.junit.jupiter:junit-jupiter:5.12.2=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
51+
org.junit.platform:junit-platform-commons:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
52+
org.junit.platform:junit-platform-engine:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
53+
org.junit.platform:junit-platform-launcher:1.14.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
5354
org.objenesis:objenesis:2.4=integTestRuntimeClasspath,testRuntimeClasspath
5455
org.opentest4j:opentest4j:1.3.0=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
5556
org.slf4j:slf4j-api:1.7.30=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2014-2021 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nebula.plugin.plugin
17+
18+
19+
import nebula.plugin.publishing.NebulaOssPublishingExtension
20+
import org.gradle.api.Plugin
21+
import org.gradle.api.Project
22+
import org.gradle.api.provider.ProviderFactory
23+
24+
import javax.inject.Inject
25+
26+
/**
27+
* Provide an environment for a Gradle plugin
28+
*/
29+
class NebulaRootPlugin implements Plugin<Project> {
30+
static final NEBULA_PLUGIN_IDS = ['com.netflix.nebula.contacts',
31+
'com.netflix.nebula.dependency-lock',
32+
'com.netflix.nebula.info',
33+
'com.netflix.nebula.maven-apache-license',
34+
'com.netflix.nebula.maven-publish',
35+
'com.netflix.nebula.publish-verification',
36+
'com.netflix.nebula.release',
37+
'com.netflix.nebula.oss-publishing']
38+
39+
static final PLUGIN_IDS = NEBULA_PLUGIN_IDS
40+
41+
private final ProviderFactory providers
42+
private boolean isPluginPublishingValidation
43+
44+
@Inject
45+
NebulaRootPlugin(ProviderFactory providerFactory) {
46+
this.providers = providerFactory
47+
}
48+
49+
@Override
50+
void apply(Project project) {
51+
this.isPluginPublishingValidation = project.gradle.startParameter.taskNames.contains('--validate-only')
52+
project.with {
53+
def nebulaOssPublishingExtension = project.rootProject.extensions.findByType(NebulaOssPublishingExtension) ?: project.rootProject.extensions.create("nebulaOssPublishing", NebulaOssPublishingExtension)
54+
nebulaOssPublishingExtension.packageGroup.set("com.netflix")
55+
56+
PLUGIN_IDS.each { plugins.apply(it) }
57+
58+
59+
if (!group) {
60+
group = 'com.netflix.nebula'
61+
}
62+
}
63+
}
64+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package nebula.plugin.plugin
2+
3+
import nebula.test.dsl.*
4+
import nebula.test.dsl.TestKitAssertions.assertThat
5+
import org.ajoberstar.grgit.Grgit
6+
import org.junit.jupiter.api.BeforeEach
7+
import org.junit.jupiter.api.Test
8+
import org.junit.jupiter.api.io.TempDir
9+
import java.io.File
10+
11+
internal class IntegrationTest {
12+
@TempDir
13+
lateinit var projectDir: File
14+
15+
@TempDir
16+
lateinit var remoteGitDir: File
17+
18+
lateinit var runner: TestProjectRunner
19+
lateinit var localCopy: Grgit
20+
21+
@BeforeEach
22+
fun beforeEach() {
23+
val remoteGit = Grgit.init {
24+
this.dir = remoteGitDir
25+
}
26+
localCopy = Grgit.clone {
27+
this.dir = projectDir
28+
this.uri = remoteGitDir.toURI().toString()
29+
}
30+
projectDir.resolve(".gitignore").writeText("""
31+
.gradle/
32+
""")
33+
runner = testProject(projectDir) {
34+
rootProject {
35+
plugins {
36+
id("com.netflix.nebula.root")
37+
}
38+
}
39+
subProject("library") {
40+
plugins {
41+
id("com.netflix.nebula.info")
42+
id("com.netflix.nebula.maven-publish")
43+
id("com.netflix.nebula.library")
44+
}
45+
src {
46+
main {
47+
java(
48+
"example/Main.java",
49+
//language=java
50+
"""
51+
package example;
52+
class Main {
53+
public static void main(String[] args) {
54+
System.out.println("Hello world!");
55+
}
56+
}
57+
"""
58+
)
59+
}
60+
}
61+
}
62+
subProject("plugin") {
63+
plugins {
64+
id("java-gradle-plugin")
65+
id("com.netflix.nebula.info")
66+
id("com.netflix.nebula.maven-publish")
67+
id("com.netflix.nebula.plugin-plugin")
68+
}
69+
rawBuildScript("""
70+
gradlePlugin {
71+
plugins {
72+
create("example") {
73+
id = "com.netflix.example"
74+
displayName = "example"
75+
description = "S"
76+
implementationClass = "example.MyPlugin"
77+
tags.set(listOf("nebula"))
78+
}
79+
}
80+
}
81+
""")
82+
src {
83+
main {
84+
java(
85+
"example/Main.java",
86+
//language=java
87+
"""
88+
package example;
89+
import org.gradle.api.Project;
90+
91+
class MyPlugin implements Plugin<Project> {
92+
@Override
93+
public void apply(Project project) {
94+
}
95+
}
96+
"""
97+
)
98+
}
99+
}
100+
}
101+
}
102+
localCopy.add {
103+
this.patterns = setOf(".")
104+
}
105+
localCopy.commit {
106+
message = "Initial"
107+
}
108+
}
109+
110+
@Test
111+
fun `test final`() {
112+
localCopy.tag.add {
113+
name = "v0.0.1"
114+
}
115+
val result = runner.run(
116+
"final",
117+
"-PnetflixOss.username=user",
118+
"-PnetflixOss.password=password",
119+
"-Psonatype.username=user",
120+
"-Psonatype.password=password",
121+
"--dry-run",
122+
"--stacktrace"
123+
)
124+
assertThat(result.output).contains(":initializeSonatypeStagingRepository SKIPPED")
125+
126+
// library publication
127+
assertThat(result.output).contains("library:publishNebulaPublicationToSonatypeRepository SKIPPED")
128+
129+
// plugin publication
130+
assertThat(result.output).contains("plugin:publishExamplePluginMarkerMavenPublicationToSonatypeRepository SKIPPED")
131+
assertThat(result.output).contains("plugin:publishNebulaPublicationToSonatypeRepository SKIPPED")
132+
133+
// global
134+
assertThat(result.output).contains(":publishNebulaPublicationToSonatypeRepository SKIPPED")
135+
assertThat(result.output).contains(":closeSonatypeStagingRepository SKIPPED")
136+
assertThat(result.output).contains(":releaseSonatypeStagingRepository SKIPPED")
137+
assertThat(result.output).contains(":closeAndReleaseSonatypeStagingRepository SKIPPED")
138+
assertThat(result.output).contains(":final SKIPPED")
139+
}
140+
}

0 commit comments

Comments
 (0)