| @@ -1,28 +1,39 | |||||
| 1 | plugins { |
|
1 | plugins { | |
| 2 | id "java-library" |
|
2 | id "java-library" | |
| 3 | id "ivy-publish" |
|
3 | id "ivy-publish" | |
| 4 | } |
|
4 | } | |
| 5 |
|
5 | |||
| 6 | java { |
|
6 | java { | |
| 7 | withJavadocJar() |
|
7 | withJavadocJar() | |
| 8 | withSourcesJar() |
|
8 | withSourcesJar() | |
|
|
9 | toolchain { | |||
|
|
10 | languageVersion = JavaLanguageVersion.of(17) | |||
|
|
11 | } | |||
| 9 | } |
|
12 | } | |
| 10 |
|
13 | |||
| 11 | dependencies { |
|
14 | dependencies { | |
| 12 | api gradleApi() |
|
15 | api gradleApi() | |
| 13 | } |
|
16 | } | |
| 14 |
|
17 | |||
| 15 | task printVersion{ |
|
18 | task printVersion{ | |
| 16 | doLast { |
|
19 | doLast { | |
| 17 |
println "project: $project.group |
|
20 | println "project: $project.group:$project.name:$project.version" | |
| 18 | println "jar: ${->jar.archiveFileName.get()}" |
|
21 | println "jar: ${->jar.archiveFileName.get()}" | |
| 19 | } |
|
22 | } | |
| 20 | } |
|
23 | } | |
| 21 |
|
24 | |||
| 22 | publishing { |
|
25 | publishing { | |
| 23 | repositories { |
|
26 | repositories { | |
| 24 | ivy { |
|
27 | ivy { | |
| 25 | url "${System.properties["user.home"]}/ivy-repo" |
|
28 | url "${System.properties["user.home"]}/ivy-repo" | |
| 26 | } |
|
29 | } | |
| 27 | } |
|
30 | } | |
|
|
31 | publications { | |||
|
|
32 | ivy(IvyPublication) { | |||
|
|
33 | from components.java | |||
|
|
34 | descriptor.description { | |||
|
|
35 | text = providers.provider({ description }) | |||
|
|
36 | } | |||
|
|
37 | } | |||
|
|
38 | } | |||
| 28 | } No newline at end of file |
|
39 | } | |
| @@ -1,54 +1,64 | |||||
| 1 | package org.implab.gradle.common; |
|
1 | package org.implab.gradle.common; | |
| 2 |
|
2 | |||
| 3 | import javax.inject.Inject; |
|
3 | import javax.inject.Inject; | |
| 4 |
|
4 | |||
| 5 | import org.gradle.api.Action; |
|
5 | import org.gradle.api.Action; | |
| 6 | import org.gradle.api.NamedDomainObjectProvider; |
|
6 | import org.gradle.api.NamedDomainObjectProvider; | |
| 7 | import org.gradle.api.Plugin; |
|
7 | import org.gradle.api.Plugin; | |
| 8 | import org.gradle.api.Project; |
|
8 | import org.gradle.api.Project; | |
| 9 | import org.gradle.api.Task; |
|
9 | import org.gradle.api.Task; | |
| 10 | import org.gradle.api.artifacts.Configuration; |
|
10 | import org.gradle.api.artifacts.Configuration; | |
| 11 | import org.gradle.api.file.Directory; |
|
11 | import org.gradle.api.file.Directory; | |
| 12 | import org.gradle.api.tasks.TaskProvider; |
|
12 | import org.gradle.api.tasks.TaskProvider; | |
|
|
13 | import org.implab.gradle.common.utils.ExtraProps; | |||
| 13 |
|
14 | |||
| 14 | /** Project configuration traits */ |
|
15 | /** Project configuration traits */ | |
| 15 | public interface ProjectMixin { |
|
16 | public interface ProjectMixin { | |
| 16 | @Inject |
|
17 | @Inject | |
| 17 | Project getProject(); |
|
18 | Project getProject(); | |
| 18 |
|
19 | |||
| 19 | /** registers the new task */ |
|
20 | /** registers the new task */ | |
| 20 | default <T extends Task> TaskProvider<T> task(String name, Class<T> clazz, Action<? super T> configure) { |
|
21 | default <T extends Task> TaskProvider<T> task(String name, Class<T> clazz, Action<? super T> configure) { | |
| 21 | return getProject().getTasks().register(name, clazz, configure); |
|
22 | return getProject().getTasks().register(name, clazz, configure); | |
| 22 | } |
|
23 | } | |
| 23 |
|
24 | |||
| 24 | /** Registers the new configuration */ |
|
25 | /** Registers the new configuration */ | |
| 25 | default NamedDomainObjectProvider<Configuration> configuration(String name, Action<? super Configuration> configure) { |
|
26 | default NamedDomainObjectProvider<Configuration> configuration(String name, Action<? super Configuration> configure) { | |
| 26 | return getProject().getConfigurations().register(name, configure); |
|
27 | return getProject().getConfigurations().register(name, configure); | |
| 27 | } |
|
28 | } | |
| 28 |
|
29 | |||
| 29 | /** Returns the project directory */ |
|
30 | /** Returns the project directory */ | |
| 30 | default Directory projectDirectory() { |
|
31 | default Directory projectDirectory() { | |
| 31 | return getProject().getLayout().getProjectDirectory(); |
|
32 | return getProject().getLayout().getProjectDirectory(); | |
| 32 | } |
|
33 | } | |
| 33 |
|
34 | |||
| 34 | /** Applies and returns the specified plugin, the plugin is applied only once. */ |
|
35 | /** Applies and returns the specified plugin, the plugin is applied only once. */ | |
| 35 | default <T extends Plugin<Project>> T plugin(Class<T> clazz) { |
|
36 | default <T extends Plugin<Project>> T plugin(Class<T> clazz) { | |
| 36 | getProject().getPluginManager().apply(clazz); |
|
37 | getProject().getPluginManager().apply(clazz); | |
| 37 | return getProject().getPlugins().findPlugin(clazz); |
|
38 | return getProject().getPlugins().findPlugin(clazz); | |
| 38 | } |
|
39 | } | |
| 39 |
|
40 | |||
|
|
41 | /** | |||
|
|
42 | * @param classes The list of classes to register as extensions | |||
|
|
43 | */ | |||
|
|
44 | default void exportClasses(Class<?>... classes) { | |||
|
|
45 | var props = ExtraProps.of(getProject()); | |||
|
|
46 | for (var clazz : classes) | |||
|
|
47 | props.put(clazz.getSimpleName(), clazz); | |||
|
|
48 | } | |||
|
|
49 | ||||
| 40 | /** Creates and register a new project extension. |
|
50 | /** Creates and register a new project extension. | |
| 41 | * |
|
51 | * | |
| 42 | * @param <T> The type of the extension |
|
52 | * @param <T> The type of the extension | |
| 43 | * @param extensionName The name of the extension in the project |
|
53 | * @param extensionName The name of the extension in the project | |
| 44 | * @param clazz The class of the extension |
|
54 | * @param clazz The class of the extension | |
| 45 | * @return the newly created extension |
|
55 | * @return the newly created extension | |
| 46 | */ |
|
56 | */ | |
| 47 | default <T> T extension(String extensionName, Class<T> clazz) { |
|
57 | default <T> T extension(String extensionName, Class<T> clazz) { | |
| 48 | T extension = getProject().getObjects().newInstance(clazz); |
|
58 | T extension = getProject().getObjects().newInstance(clazz); | |
| 49 | getProject().getExtensions().add(extensionName, extension); |
|
59 | getProject().getExtensions().add(extensionName, extension); | |
| 50 | return extension; |
|
60 | return extension; | |
| 51 | } |
|
61 | } | |
| 52 |
|
62 | |||
| 53 | } |
|
63 | } | |
| 54 |
|
64 | |||
| @@ -1,16 +1,16 | |||||
| 1 | package org.implab.gradle.common.utils; |
|
1 | package org.implab.gradle.common.utils; | |
| 2 |
|
2 | |||
| 3 | import java.util.Map; |
|
3 | import java.util.Map; | |
| 4 |
|
4 | |||
| 5 | import org.gradle.api.plugins.ExtensionAware; |
|
5 | import org.gradle.api.plugins.ExtensionAware; | |
| 6 |
|
6 | |||
| 7 | public class ExtraProps { |
|
7 | public class ExtraProps { | |
| 8 |
|
8 | |||
| 9 | public static Map<String, Object> of(Object target) { |
|
9 | public static Map<String, Object> of(Object target) { | |
| 10 | return switch (target) { |
|
10 | if (target instanceof ExtensionAware ext) | |
| 11 |
|
|
11 | return ext.getExtensions().getExtraProperties().getProperties(); | |
| 12 | default -> Map.of(); |
|
12 | else | |
| 13 | }; |
|
13 | return Map.of(); | |
| 14 | } |
|
14 | } | |
| 15 |
|
15 | |||
| 16 | } |
|
16 | } | |
General Comments 0
You need to be logged in to leave comments.
Login now
