##// END OF EJS Templates
WIP setup pulication tasks to local repository
cin -
r1:e91c2403acf8 default
parent child
Show More
@@ -1,28 +1,39
1 1 plugins {
2 2 id "java-library"
3 3 id "ivy-publish"
4 4 }
5 5
6 6 java {
7 7 withJavadocJar()
8 8 withSourcesJar()
9 toolchain {
10 languageVersion = JavaLanguageVersion.of(17)
11 }
9 12 }
10 13
11 14 dependencies {
12 15 api gradleApi()
13 16 }
14 17
15 18 task printVersion{
16 19 doLast {
17 println "project: $project.groupId:$project.name:$project.version"
20 println "project: $project.group:$project.name:$project.version"
18 21 println "jar: ${->jar.archiveFileName.get()}"
19 22 }
20 23 }
21 24
22 25 publishing {
23 26 repositories {
24 27 ivy {
25 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 39 } No newline at end of file
@@ -1,54 +1,64
1 1 package org.implab.gradle.common;
2 2
3 3 import javax.inject.Inject;
4 4
5 5 import org.gradle.api.Action;
6 6 import org.gradle.api.NamedDomainObjectProvider;
7 7 import org.gradle.api.Plugin;
8 8 import org.gradle.api.Project;
9 9 import org.gradle.api.Task;
10 10 import org.gradle.api.artifacts.Configuration;
11 11 import org.gradle.api.file.Directory;
12 12 import org.gradle.api.tasks.TaskProvider;
13 import org.implab.gradle.common.utils.ExtraProps;
13 14
14 15 /** Project configuration traits */
15 16 public interface ProjectMixin {
16 17 @Inject
17 18 Project getProject();
18 19
19 20 /** registers the new task */
20 21 default <T extends Task> TaskProvider<T> task(String name, Class<T> clazz, Action<? super T> configure) {
21 22 return getProject().getTasks().register(name, clazz, configure);
22 23 }
23 24
24 25 /** Registers the new configuration */
25 26 default NamedDomainObjectProvider<Configuration> configuration(String name, Action<? super Configuration> configure) {
26 27 return getProject().getConfigurations().register(name, configure);
27 28 }
28 29
29 30 /** Returns the project directory */
30 31 default Directory projectDirectory() {
31 32 return getProject().getLayout().getProjectDirectory();
32 33 }
33 34
34 35 /** Applies and returns the specified plugin, the plugin is applied only once. */
35 36 default <T extends Plugin<Project>> T plugin(Class<T> clazz) {
36 37 getProject().getPluginManager().apply(clazz);
37 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 50 /** Creates and register a new project extension.
41 51 *
42 52 * @param <T> The type of the extension
43 53 * @param extensionName The name of the extension in the project
44 54 * @param clazz The class of the extension
45 55 * @return the newly created extension
46 56 */
47 57 default <T> T extension(String extensionName, Class<T> clazz) {
48 58 T extension = getProject().getObjects().newInstance(clazz);
49 59 getProject().getExtensions().add(extensionName, extension);
50 60 return extension;
51 61 }
52 62
53 63 }
54 64
@@ -1,16 +1,16
1 1 package org.implab.gradle.common.utils;
2 2
3 3 import java.util.Map;
4 4
5 5 import org.gradle.api.plugins.ExtensionAware;
6 6
7 7 public class ExtraProps {
8 8
9 9 public static Map<String, Object> of(Object target) {
10 return switch (target) {
11 case ExtensionAware ext -> ext.getExtensions().getExtraProperties().getProperties();
12 default -> Map.of();
13 };
10 if (target instanceof ExtensionAware ext)
11 return ext.getExtensions().getExtraProperties().getProperties();
12 else
13 return Map.of();
14 14 }
15 15
16 16 }
@@ -1,2 +1,2
1 groupId=org.implab.gradle
1 group=org.implab.gradle
2 2 version=1.0 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now