/*
 * Copyright 2014 Etienne Studer
 *
 * 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 nu.studer.gradle.plugindev;

import org.gradle.api.JavaVersion;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.dsl.RepositoryHandler;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.bundling.Jar;
import org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * Plugin for Gradle plugin development. The PluginDevPlugin creates a MavenPublication of the Gradle plugin project that the plugin is applied to. Almost all configuration can
 * happen in one central location through the 'plugindev' extension. The PluginDevPlugin ensures that the publication matches all requirements given by MavenCentral and the Gradle
 * Plugin Portal.
 */
@SuppressWarnings("unused")
public class PluginDevPlugin implements Plugin<Project> {

    // task names
    public static final String SOURCES_JAR_TASK_NAME = "sourcesJar";
    public static final String DOCS_JAR_TASK_NAME = "docsJar";

    // miscellaneous
    private static final JavaVersion MINIMUM_GRADLE_JAVA_VERSION = JavaVersion.VERSION_1_8;

    private static final Logger LOGGER = LoggerFactory.getLogger(PluginDevPlugin.class);

    public void apply(Project project) {
        // add the MavenCentral repository
        RepositoryHandler repositories = project.getRepositories();
        repositories.add(repositories.mavenCentral());
        LOGGER.debug("Added repository 'MavenCentral'");

        // apply the JavaGradlePluginPlugin
        Class<JavaGradlePluginPlugin> pluginClass = JavaGradlePluginPlugin.class;
        project.getPlugins().apply(pluginClass);
        LOGGER.debug("Applied plugin '" + pluginClass.getSimpleName() + "'");

        // set the source/target compatibility of Java compile and optionally of Groovy compile
        JavaPluginExtension javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);
        javaExtension.setSourceCompatibility(MINIMUM_GRADLE_JAVA_VERSION);
        javaExtension.setTargetCompatibility(MINIMUM_GRADLE_JAVA_VERSION);
        LOGGER.debug("Set Java source and target compatibility to " + MINIMUM_GRADLE_JAVA_VERSION);

        // add a MANIFEST file with basic build implementation
        HashMap<String, String> attrs = new HashMap<>();
        attrs.put("Build-Date", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        attrs.put("Build-JDK", System.getProperty("java.version"));
        attrs.put("Build-Gradle", project.getGradle().getGradleVersion());
        project.getTasks().withType(Jar.class).configureEach(jar -> jar.getManifest().attributes(attrs));
        LOGGER.debug("Configured jar files with manifest attributes");
    }

}

@@ -923,32 +923,86 @@
 lePluginPlugin;%0A
+import org.gradle.plugin.devel.tasks.ValidatePlugins;%0A
 import org.slf4j
@@ -3452,16 +3452,265 @@
 butes%22);
+%0A%0A        // enable strict validation%0A        project.getTasks().withType(ValidatePlugins.class).configureEach(t -%3E %7B%0A                t.getFailOnWarning().set(true);%0A                t.getEnableStricterValidation().set(true);%0A            %7D%0A        );
 %0A    %7D%0A%0A

Enable stricter validation and fail on warnings