-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DSL for module dependencies that cannot be defined in module-info
- Loading branch information
Showing
4 changed files
with
156 additions
and
66 deletions.
There are no files selected for viewing
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
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
27 changes: 27 additions & 0 deletions
27
src/main/java/org/gradlex/javamodule/dependencies/dsl/AllDirectives.java
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,27 @@ | ||
package org.gradlex.javamodule.dependencies.dsl; | ||
|
||
import org.gradle.api.tasks.SourceSet; | ||
import org.gradlex.javamodule.dependencies.JavaModuleDependenciesExtension; | ||
|
||
abstract public class AllDirectives extends GradleOnlyDirectives { | ||
|
||
public AllDirectives(SourceSet sourceSet, SourceSet mainSourceSet, JavaModuleDependenciesExtension javaModuleDependencies) { | ||
super(sourceSet, mainSourceSet, javaModuleDependencies); | ||
} | ||
|
||
public void requires(String moduleName) { | ||
add(sourceSet.getImplementationConfigurationName(), moduleName); | ||
} | ||
|
||
public void requiresTransitive(String moduleName) { | ||
add(sourceSet.getApiConfigurationName(), moduleName); | ||
} | ||
|
||
public void requiresStatic(String moduleName) { | ||
add(sourceSet.getCompileOnlyConfigurationName(), moduleName); | ||
} | ||
|
||
public void requiresStaticTransitive(String moduleName) { | ||
add(sourceSet.getCompileOnlyApiConfigurationName(), moduleName); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/org/gradlex/javamodule/dependencies/dsl/GradleOnlyDirectives.java
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,36 @@ | ||
package org.gradlex.javamodule.dependencies.dsl; | ||
|
||
import org.gradle.api.artifacts.Dependency; | ||
import org.gradle.api.artifacts.dsl.DependencyHandler; | ||
import org.gradle.api.tasks.SourceSet; | ||
import org.gradlex.javamodule.dependencies.JavaModuleDependenciesExtension; | ||
|
||
import javax.inject.Inject; | ||
|
||
public abstract class GradleOnlyDirectives { | ||
|
||
@Inject | ||
protected abstract DependencyHandler getDependencies(); | ||
|
||
protected final SourceSet sourceSet; | ||
protected final SourceSet mainSourceSet; | ||
protected final JavaModuleDependenciesExtension javaModuleDependencies; | ||
|
||
public GradleOnlyDirectives(SourceSet sourceSet, SourceSet mainSourceSet, JavaModuleDependenciesExtension javaModuleDependencies) { | ||
this.sourceSet = sourceSet; | ||
this.mainSourceSet = mainSourceSet; | ||
this.javaModuleDependencies = javaModuleDependencies; | ||
} | ||
|
||
protected void add(String scope, String moduleName) { | ||
getDependencies().addProvider(scope, javaModuleDependencies.create(moduleName, mainSourceSet)); | ||
} | ||
|
||
public void runtimeOnly(String moduleName) { | ||
add(sourceSet.getRuntimeOnlyConfigurationName(), moduleName); | ||
} | ||
|
||
public void annotationProcessor(String moduleName) { | ||
add(sourceSet.getAnnotationProcessorConfigurationName(), moduleName); | ||
} | ||
} |