001/*
002 * Copyright 2017-2022 original authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.micronaut.maven.aot;
017
018import io.micronaut.maven.core.MojoUtils;
019import io.micronaut.maven.services.CompilerService;
020import io.micronaut.maven.services.DependencyResolutionService;
021import io.micronaut.maven.services.ExecutorService;
022import org.apache.maven.execution.MavenSession;
023import org.apache.maven.plugins.annotations.LifecyclePhase;
024import org.apache.maven.plugins.annotations.Mojo;
025import org.apache.maven.plugins.annotations.ResolutionScope;
026import org.apache.maven.project.MavenProject;
027import org.apache.maven.toolchain.ToolchainManager;
028
029import javax.inject.Inject;
030
031/**
032 * Standalone Micronaut AOT analysis goal.
033 *
034 * @author Álvaro Sánchez-Mariscal
035 * @since 3.2.0
036 */
037@Mojo(name = AbstractAotAnalysisMojo.NAME, defaultPhase = LifecyclePhase.PREPARE_PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
038public class AotAnalysisMojo extends AbstractAotAnalysisMojo {
039
040    @Inject
041    @SuppressWarnings("CdiInjectionPointsInspection")
042    public AotAnalysisMojo(CompilerService compilerService,
043                           ExecutorService executorService,
044                           MavenProject mavenProject,
045                           DependencyResolutionService dependencyResolutionService,
046                           MavenSession mavenSession,
047                           ToolchainManager toolchainManager) {
048        super(compilerService, executorService, mavenProject, dependencyResolutionService, mavenSession, toolchainManager);
049    }
050
051    @Override
052    protected boolean shouldExecute() {
053        if (MojoUtils.hasMicronautMavenPlugin(mavenProject)) {
054            getLog().info("Skipping standalone AOT analysis because micronaut-maven-plugin already owns AOT execution for this build");
055            return false;
056        }
057        return true;
058    }
059
060    @Override
061    protected boolean alignRuntimeWithPackaging() {
062        return false;
063    }
064}