Skip to content

Commit 0061a7f

Browse files
jmcampaniniuschi2000
authored andcommitted
add an sls configuration (palantir#94)
1 parent e43924a commit 0061a7f

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ As part of package creation, this plugin will create three shell scripts:
9898
In addition to creating these scripts, this plugin will merge the entire
9999
contents of `${projectDir}/service` and `${projectDir}/var` into the package.
100100

101+
The plugin also exposes the tar file as an artifact in the `sls` configuration, making it easy to
102+
share the artifact between sibling Gradle projects. For example:
103+
104+
```groovy
105+
configurations { tarballs }
106+
107+
dependencies {
108+
tarballs project(path: ':other-project', configuration: 'sls')
109+
}
110+
```
111+
101112
Running with Gradle
102113
-------------------
103114
To run the main class using Gradle, run the `run` task.

src/main/groovy/com/palantir/gradle/javadist/JavaDistributionPlugin.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import java.nio.file.Paths
2727
class JavaDistributionPlugin implements Plugin<Project> {
2828

2929
private static final String GROUP_NAME = "Distribution"
30+
private static final String SLS_CONFIGURATION_NAME = "sls"
3031

3132
void apply(Project project) {
3233
// force application of java
@@ -147,6 +148,9 @@ class JavaDistributionPlugin implements Plugin<Project> {
147148
it.description = "Runs the specified project using configured mainClass and with default args."
148149
})
149150

151+
project.configurations.create(SLS_CONFIGURATION_NAME)
152+
project.artifacts.add(SLS_CONFIGURATION_NAME, distTar)
153+
150154
project.afterEvaluate {
151155
manifestClasspathJar.configure(ext)
152156
startScripts.configure(ext)

src/test/groovy/com/palantir/gradle/javadist/GradleTestSpec.groovy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.palantir.gradle.javadist
33
import com.energizedwork.spock.extensions.TempDirectory
44
import groovy.transform.CompileStatic
55
import groovy.transform.TypeCheckingMode
6+
import nebula.test.multiproject.MultiProjectIntegrationHelper
67
import org.gradle.testkit.runner.BuildResult
78
import org.gradle.testkit.runner.GradleRunner
89
import org.gradle.testkit.runner.TaskOutcome
@@ -11,12 +12,16 @@ import spock.lang.Specification
1112
import java.nio.file.Files
1213

1314
public class GradleTestSpec extends Specification {
14-
@TempDirectory
15+
@TempDirectory(clean = false)
1516
File projectDir
1617
File buildFile
18+
File settingsFile
19+
MultiProjectIntegrationHelper helper
1720

1821
def setup() {
1922
buildFile = file("build.gradle")
23+
settingsFile = new File(projectDir, 'settings.gradle')
24+
helper = new MultiProjectIntegrationHelper(projectDir, settingsFile)
2025
println("Build directory: \n" + projectDir.absolutePath)
2126
}
2227

src/test/groovy/com/palantir/gradle/javadist/JavaDistributionPluginTests.groovy

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.palantir.gradle.javadist
1818
import com.fasterxml.jackson.databind.ObjectMapper
1919
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
2020
import org.gradle.testkit.runner.BuildResult
21+
import org.gradle.testkit.runner.TaskOutcome
2122

2223
class JavaDistributionPluginTests extends GradleTestSpec {
2324

@@ -342,7 +343,47 @@ class JavaDistributionPluginTests extends GradleTestSpec {
342343
then:
343344
buildResult.output =~ ("before: distTar: ${projectDir}/build/distributions/my-service.tgz")
344345
buildResult.output =~ ("after: distTar: ${projectDir}/build/distributions/my-service.tgz")
346+
}
347+
348+
def 'exposes an artifact through the sls configuration'() {
349+
given:
350+
helper.addSubproject('parent', '''
351+
plugins {
352+
id 'com.palantir.java-distribution'
353+
id 'java'
354+
}
355+
repositories { jcenter() }
356+
version '0.1'
357+
distribution {
358+
serviceName "my-service"
359+
mainClass "dummy.service.MainClass"
360+
args "hello"
361+
}
362+
''')
363+
364+
helper.addSubproject('child', '''
365+
configurations {
366+
fromOtherProject
367+
}
368+
dependencies {
369+
fromOtherProject project(path: ':parent', configuration: 'sls')
370+
}
371+
task untar(type: Copy) {
372+
// ensures the artifact is built by depending on the configuration
373+
dependsOn configurations.fromOtherProject
345374
375+
// copy the contents of the tarball
376+
from tarTree(configurations.fromOtherProject.singleFile)
377+
into 'build/exploded'
378+
}
379+
''')
380+
381+
when:
382+
BuildResult buildResult = runSuccessfully(':child:untar')
383+
384+
then:
385+
buildResult.task(':parent:distTar').outcome == TaskOutcome.SUCCESS
386+
file('child/build/exploded/my-service-0.1/deployment/manifest.yml')
346387
}
347388

348389
private static def createUntarBuildFile(buildFile) {

0 commit comments

Comments
 (0)