Skip to content

Commit

Permalink
better handling for missing source set
Browse files Browse the repository at this point in the history
  • Loading branch information
harrel56 committed Sep 29, 2023
1 parent c4fc431 commit 442f557
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/simple/src/main/java/Example.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
public class Example {
public String[] hello;
public String[] hello2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;

import java.util.Optional;
import java.util.Set;

public class JavaToTsPlugin implements Plugin<Project> {
Expand Down Expand Up @@ -42,9 +43,9 @@ public void apply(Project project) {

private Provider<SourceSet> getDefaultSourceSet(Project project) {
return project.getProviders().provider(() ->
project.getExtensions()
.getByType(SourceSetContainer.class)
.findByName("main"));
Optional.ofNullable(project.getExtensions().findByType(SourceSetContainer.class))
.map(s -> s.findByName("main"))
.orElseThrow(() -> new IllegalArgumentException("Source set was not provided and there was no source set named 'main'")));
}

private Provider<RegularFile> getDefaultOutput(Project project) {
Expand Down

0 comments on commit 442f557

Please sign in to comment.