-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix service files not merged with shadow plugin
This commit fixes shadow jar building, by making sure that the generated jar merges service files. Fixes #406
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
functional-tests/src/test/groovy/io/micronaut/gradle/shadow/ShadowJarSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package io.micronaut.gradle.shadow | ||
|
||
import io.micronaut.gradle.fixtures.AbstractFunctionalTest | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import spock.lang.Issue | ||
|
||
class ShadowJarSpec extends AbstractFunctionalTest { | ||
|
||
@Issue("https://github.com/micronaut-projects/micronaut-gradle-plugin/issues/406") | ||
def "merges service files when building shadow jar"() { | ||
def shadowJar = file("build/libs/hello-world-1.0-all.jar") | ||
|
||
given: | ||
settingsFile << "rootProject.name = 'hello-world'" | ||
buildFile << """ | ||
plugins { | ||
id "io.micronaut.minimal.application" | ||
id "com.github.johnrengelman.shadow" version "7.1.0" | ||
} | ||
version = "1.0" | ||
micronaut { | ||
version "3.4.0" | ||
runtime "none" | ||
processing { | ||
annotations("example.*") | ||
} | ||
} | ||
$repositoriesBlock | ||
mainClassName="example.Application" | ||
dependencies { | ||
annotationProcessor("info.picocli:picocli-codegen") | ||
implementation("info.picocli:picocli") | ||
implementation("io.micronaut.picocli:micronaut-picocli") | ||
} | ||
tasks.register("shadowRun") { | ||
def shadowJar = tasks.named("shadowJar") | ||
inputs.file(shadowJar.flatMap { it.archiveFile }) | ||
doLast { | ||
def exec = services.get(ExecOperations) | ||
exec.javaexec { | ||
it.classpath = files(shadowJar.flatMap { it.archiveFile }.get()) | ||
it.main = "example.Application" | ||
} | ||
} | ||
} | ||
""" | ||
testProjectDir.newFolder("src", "main", "java", "example") | ||
|
||
file("src/main/java/example/Application.java") << """package example; | ||
import io.micronaut.configuration.picocli.PicocliRunner; | ||
import picocli.CommandLine.Command; | ||
@Command(name = "demo", description = "...", mixinStandardHelpOptions = true) | ||
public class Application implements Runnable { | ||
public static void main(String[] args) { | ||
PicocliRunner.run(Application.class, args); | ||
} | ||
public void run() { | ||
System.out.println("Hello, all!"); | ||
} | ||
}""" | ||
|
||
when: | ||
def result = build('shadowRun') | ||
|
||
then: | ||
result.task(":shadowJar").outcome == TaskOutcome.SUCCESS | ||
result.task(":shadowRun").outcome == TaskOutcome.SUCCESS | ||
shadowJar.exists() | ||
result.output.contains("Hello, all!") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters