-
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.
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
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
47 changes: 47 additions & 0 deletions
47
src/main/java/org/gradlex/javamodule/dependencies/JavaModuleVersionsPlugin.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,47 @@ | ||
/* | ||
* Copyright the GradleX team. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.gradlex.javamodule.dependencies; | ||
|
||
import org.gradle.api.NonNullApi; | ||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.artifacts.Configuration; | ||
import org.gradle.api.plugins.JavaPlatformPlugin; | ||
import org.gradle.api.plugins.JavaPlugin; | ||
import org.gradlex.javamodule.dependencies.dsl.ModuleVersions; | ||
|
||
@SuppressWarnings("unused") | ||
@NonNullApi | ||
public abstract class JavaModuleVersionsPlugin implements Plugin<Project> { | ||
|
||
@Override | ||
public void apply(Project project) { | ||
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> setupForProject(project)); | ||
project.getPlugins().withType(JavaPlatformPlugin.class, javaPlugin -> setupForProject(project)); | ||
} | ||
|
||
private void setupForProject(Project project) { | ||
project.getPlugins().apply(JavaModuleDependenciesPlugin.class); | ||
JavaModuleDependenciesExtension javaModuleDependencies = project.getExtensions().getByType(JavaModuleDependenciesExtension.class); | ||
Configuration configuration = project.getConfigurations().findByName(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME); | ||
if (configuration == null) { | ||
configuration = project.getConfigurations().getByName(JavaPlatformPlugin.API_CONFIGURATION_NAME); | ||
} | ||
project.getExtensions().create("moduleInfo", ModuleVersions.class, configuration, javaModuleDependencies); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/org/gradlex/javamodule/dependencies/dsl/ModuleVersions.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,52 @@ | ||
/* | ||
* Copyright the GradleX team. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.gradlex.javamodule.dependencies.dsl; | ||
|
||
import org.gradle.api.Action; | ||
import org.gradle.api.artifacts.Configuration; | ||
import org.gradle.api.artifacts.DependencyConstraint; | ||
import org.gradle.api.artifacts.MutableVersionConstraint; | ||
import org.gradle.api.artifacts.dsl.DependencyHandler; | ||
import org.gradlex.javamodule.dependencies.JavaModuleDependenciesExtension; | ||
|
||
import javax.inject.Inject; | ||
|
||
abstract public class ModuleVersions { | ||
|
||
private final Configuration configuration; | ||
protected final JavaModuleDependenciesExtension javaModuleDependencies; | ||
|
||
@Inject | ||
protected abstract DependencyHandler getDependencies(); | ||
|
||
public ModuleVersions(Configuration configuration, JavaModuleDependenciesExtension javaModuleDependencies) { | ||
this.configuration = configuration; | ||
this.javaModuleDependencies = javaModuleDependencies; | ||
} | ||
|
||
public void version(String moduleName, String version) { | ||
version(moduleName, a -> a.require(version)); | ||
} | ||
|
||
public void version(String moduleName, Action<? super MutableVersionConstraint> version) { | ||
getDependencies().getConstraints().add(configuration.getName(), javaModuleDependencies.ga(moduleName).map(ga -> { | ||
DependencyConstraint dependencyConstraint = getDependencies().getConstraints().create(ga); | ||
dependencyConstraint.version(version); | ||
return dependencyConstraint; | ||
})); | ||
} | ||
} |
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