Skip to content

Plugin sources generation #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/graalvm-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ on:
push:
branches:
- master
- '[1-9]+.[0-9]+.x'
- '[0-9]+.[0-9]+.x'
pull_request:
branches:
- master
- '[1-9]+.[0-9]+.x'
- '[0-9]+.[0-9]+.x'
jobs:
build_matrix:
if: github.repository != 'micronaut-projects/micronaut-project-template'
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ on:
push:
branches:
- master
- '[1-9]+.[0-9]+.x'
- '[0-9]+.[0-9]+.x'
pull_request:
branches:
- master
- '[1-9]+.[0-9]+.x'
- '[0-9]+.[0-9]+.x'
jobs:
build:
if: github.repository != 'micronaut-projects/micronaut-project-template'
Expand All @@ -33,13 +33,13 @@ jobs:
OSS_INDEX_USERNAME: ${{ secrets.OSS_INDEX_USERNAME }}
OSS_INDEX_PASSWORD: ${{ secrets.OSS_INDEX_PASSWORD }}
steps:
# https://github.com/actions/virtual-environments/issues/709
# https://github.com/actions/virtual-environments/issues/709
- name: "🗑 Free disk space"
run: |
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo apt-get clean
df -h
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo apt-get clean
df -h

- name: "📥 Checkout repository"
uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# Micronaut build-plugin-sourcegen

[![Maven Central](https://img.shields.io/maven-central/v/io.micronaut.build-plugin-sourcegen/micronaut-project-template.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.micronaut.project-template%22%20AND%20a:%22micronaut-project-template%22)
[![Build Status](https://github.com/micronaut-projects/micronaut-build-plugin-sourcegen/workflows/Java%20CI/badge.svg)](https://github.com/micronaut-projects/micronaut-project-template/actions)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=micronaut-projects_micronaut-template&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=micronaut-projects_micronaut-template)
[![Maven Central](https://img.shields.io/maven-central/v/io.micronaut.build-plugin-sourcegen/micronaut-project-template.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.micronaut.build.plugin.sourcegen%22%20AND%20a:%22micronaut-build-plugin-sourcegen%22)
[![Build Status](https://github.com/micronaut-projects/micronaut-build-plugin-sourcegen/workflows/Java%20CI/badge.svg)](https://github.com/micronaut-projects/micronaut-build-plugin-sourcegen/actions)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=micronaut-projects_micronaut-template&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=micronaut-projects_micronaut-build-plugin-sourcegen)
[![Revved up by Develocity](https://img.shields.io/badge/Revved%20up%20by-Develocity-06A0CE?logo=Gradle&labelColor=02303A)](https://ge.micronaut.io/scans)

Micronaut build-plugin-sourcegen
Expand Down
8 changes: 8 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
plugins {
id 'groovy-gradle-plugin'
}

repositories {
mavenCentral()
}

dependencies {
implementation(libs.sonatype.scan)
}
7 changes: 7 additions & 0 deletions buildSrc/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
versionCatalogs {
libs {
from(files("../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
plugins {
id 'io.micronaut.build.internal.build-plugin-sourcegen-base'
id "io.micronaut.build.internal.module"
id "org.sonatype.gradle.plugins.scan"
}

repositories {
maven {
setUrl("https://repo.gradle.org/gradle/libs-releases")
}
}

micronautBuild {
binaryCompatibility {
enabledAfter("1.0.0")
}
}

String ossIndexUsername = System.getenv("OSS_INDEX_USERNAME") ?: project.properties["ossIndexUsername"]
String ossIndexPassword = System.getenv("OSS_INDEX_PASSWORD") ?: project.properties["ossIndexPassword"]
boolean sonatypePluginConfigured = ossIndexUsername != null && ossIndexPassword != null
if (sonatypePluginConfigured) {
ossIndexAudit {
username = ossIndexUsername
password = ossIndexPassword
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id("io.micronaut.build.internal.build-plugin-sourcegen-base")
id("io.micronaut.build.internal.common")
}

repositories {
maven {
setUrl("https://repo.gradle.org/gradle/libs-releases")
}
}

tasks.withType(Test).configureEach {
useJUnitPlatform()
}

tasks.withType(Checkstyle).configureEach {
enabled = false
}
4 changes: 2 additions & 2 deletions config/spotless.license.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-$YEAR original authors
* Copyright 2025 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -12,4 +12,4 @@
* 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.
*/
*/
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
projectVersion=0.0.1-SNAPSHOT
projectGroup=io.micronaut.build-plugin-sourcegen
projectGroup=io.micronaut.build.plugin.sourcegen

title=Micronaut build-plugin-sourcegen
projectDesc=TODO
title=Micronaut Build Plugin Sourcegen
projectDesc=Project for generating sources of build plugin tasks
projectUrl=https://micronaut.io
githubSlug=micronaut-projects/micronaut-build-plugin-sourcegen
developers=Graeme Rocher
developers=Andriy Dmytruk

org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
org.gradle.configuration-cache=false
Expand Down
17 changes: 17 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@
micronaut = "4.7.10"
micronaut-docs = "2.0.0"
micronaut-test = "4.6.2"
micronaut-sourcegen = "1.6.1"

groovy = "4.0.24"
spock = "2.3-groovy-4.0"
gradle-plugins-api = "8.11.1"
maven-plugin-annotations = "3.9.0"
maven-core = "3.9.4"
maven-plugin-testing-harness = "3.3.0"

sonatype-scan = "3.0.0"

# Managed versions appear in the BOM
# managed-somelib = "1.0"
Expand All @@ -29,6 +37,15 @@ spock = "2.3-groovy-4.0"
[libraries]
# Core
micronaut-core = { module = 'io.micronaut:micronaut-core-bom', version.ref = 'micronaut' }
micronaut-sourcegen = { module = 'io.micronaut.sourcegen:micronaut-sourcegen-bom', version.ref = 'micronaut-sourcegen' }

gradle-plugins-api = { module = 'dev.gradleplugins:gradle-api', version.ref = 'gradle-plugins-api' }
maven-plugin-annotations = { module = 'org.apache.maven.plugin-tools:maven-plugin-annotations', version.ref = 'maven-plugin-annotations' }
maven-plugin-api = { module = 'org.apache.maven:maven-plugin-api', version.ref = 'maven-core' }
maven-core = { module = 'org.apache.maven:maven-core', version.ref = 'maven-core' }
maven-plugin-testing-harness = { module = 'org.apache.maven.plugin-testing:maven-plugin-testing-harness', version.ref = 'maven-plugin-testing-harness' }

sonatype-scan = { module = "org.sonatype.gradle.plugins:scan-gradle-plugin", version.ref = "sonatype-scan" }

#
# Managed dependencies appear in the BOM
Expand Down
3 changes: 3 additions & 0 deletions micronaut-build-plugin-sourcegen-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("io.micronaut.build.internal.build-plugin-sourcegen-module")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Copyright 2025 original authors
*
* 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
*
* https://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 io.micronaut.sourcegen.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.CLASS;

/**
* An annotation that triggers the generation of Gradle plugin and other types.
* Only single Gradle plugin should be generated. But a plugin may contain
* more than one task. Each task will have an corresponding extension method.
*
* @author Andriy Dmytruk
* @since 1.0.x
*/
@Documented
@Retention(CLASS)
@Target({ ElementType.TYPE })
public @interface GenerateGradlePlugin {

/**
* The prefix to use for all names.
* For example if the prefix is {@code Test}, task will be generated as {@code TestTask}.
* The default is the annotated class name.
*
* @return The prefix
*/
String namePrefix() default "";

/**
* Configure gradle tasks that will be generated.
*
* @return gradle task configurations
*/
GenerateGradleTask[] tasks();

/**
* The types of classes to generate.
* By default, all are generated.
*
* @return The plugin types to generate.
*/
Type[] types() default {
Type.GRADLE_TASK, Type.GRADLE_EXTENSION, Type.GRADLE_SPECIFICATION, Type.GRADLE_PLUGIN
};

/**
* @return The gradle task group that will be set for all tasks
*/
String taskGroup() default "";

/**
* @return Whether to extend the micronaut plugin
*/
boolean micronautPlugin() default true;

/**
* The coordinate of dependency to add, like
* {@code io.micronaut.jsonschema:micronaut-jsonschema-generator}.
*
* @return The dependency
*/
String dependency() default "";

/**
* Enum defining the types that could be generated.
*/
enum Type {
GRADLE_TASK,
GRADLE_SPECIFICATION,
GRADLE_EXTENSION,
GRADLE_PLUGIN
}

/**
* A configuration for generating a gradle task as part of the plugin.
*/
@interface GenerateGradleTask {

/**
* @return The prefix to use for task name.
*/
String namePrefix() default "";

/**
* @return The task configuration class name that has {@link PluginTask} annotation
*/
String source();

/**
* @return The name to use for the generated extension
*/
String extensionMethodName() default "";

/**
* @return Whether the task is cacheable
*/
boolean cacheable() default true;

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2025 original authors
*
* 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
*
* https://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 io.micronaut.sourcegen.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.CLASS;

/**
* An annotation that triggers the generation of Maven Mojo.
* A plugin can include multiple Mojos.
*
* @author Andriy Dmytruk
* @since 1.0.x
*/
@Documented
@Retention(CLASS)
@Target({ ElementType.TYPE })
@Repeatable(GenerateMavenMojo.List.class)
public @interface GenerateMavenMojo {

/**
* The prefix to use for the mojo name.
* For example if the prefix is {@code Test}, mojo will be generated as {@code TestMojo}.
* The default is the annotated class name.
*
* @return The prefix
*/
String namePrefix() default "";

/**
* @return The task configuration class name that has {@link PluginTask} annotation
*/
String source();

/**
* @return Whether to extend abstract micronaut mojo.
*/
boolean micronautPlugin() default true;

/**
* The property prefix to use for parameters generated in Maven Mojo.
*
* @see PluginTaskParameter#globalProperty()
* @return The property prefix
*/
String mavenPropertyPrefix() default "";

/**
* A container for repeated MavenMojo.
*/
@Documented
@Retention(CLASS)
@Target({ ElementType.TYPE })
@interface List {

/**
* @return Repeated annotations
*/
GenerateMavenMojo[] value();
}

}
Loading
Loading