org.apache.maven.plugin.MojoFailureException类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(17.7k)|赞(0)|评价(0)|浏览(1045)

本文整理了Java中org.apache.maven.plugin.MojoFailureException类的一些代码示例,展示了MojoFailureException类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MojoFailureException类的具体详情如下:
包路径:org.apache.maven.plugin.MojoFailureException
类名称:MojoFailureException

MojoFailureException介绍

[英]An exception occurring during the execution of a plugin (such as a compilation failure).
Throwing this exception causes a "BUILD FAILURE" message to be displayed.
[中]插件执行期间发生的异常(例如编译失败)。
引发此异常会导致显示“生成失败”消息。

代码示例

代码示例来源:origin: simpligility/android-maven-plugin

if ( contentGraphicList == null || contentGraphicList.isEmpty() )
  getLog().warn( "There are no images in " + dir.getAbsolutePath() + "/" + imageType );
  return ;
try
  getLog().info( "Deleting the old " + imageType );
    getLog().error( message );
    throw new MojoFailureException( message );
  getLog().error( e.getMessage(), e );
  throw new MojoExecutionException( e.getMessage(), e );

代码示例来源:origin: jooby-project/jooby

@Override
 public void execute() throws MojoExecutionException, MojoFailureException {
  if (mainClass == null) {
   throw new MojoExecutionException("main class not configured");
  }

  try (URLClassLoader loader = new Classpath(mavenProject).toClassLoader()) {
   Path srcdir = new File(mavenProject.getBuild().getSourceDirectory()).toPath();
   Path bindir = new File(mavenProject.getBuild().getOutputDirectory()).toPath();
   getLog().debug("Using classloader " + loader);
   getLog().debug("    source: " + srcdir);
   getLog().debug("    bin: " + bindir);
   Path output = new ApiParser(srcdir)
     .with(loader)
     .export(bindir, mainClass);
   getLog().info("API file: " + output);
  } catch (Exception x) {
   throw new MojoFailureException("ApiTool resulted in exception: ", x);
  }
 }
}

代码示例来源:origin: de.saumya.mojo/gem-maven-plugin

if(this.project.getArtifact().getFile() == null){
  File f = new File(this.project.getBuild().getDirectory(), this.project.getBuild().getFinalName() +".gem");
  if (f.exists()) {
    this.project.getArtifact().setFile(f);
if (this.gem == null && this.project.getArtifact() != null
    && this.project.getArtifact().getFile() != null
    && this.project.getArtifact().getFile().exists()) {
  final GemArtifact gemArtifact = new GemArtifact(this.project);
    throw new MojoExecutionException("not a gem artifact");
          throw new MojoFailureException("more than one gem file found, use -Dgem=... to specifiy one");
    getLog().info("use gem: " + this.gem);
    script.addArg(this.gem);

代码示例来源:origin: org.apache.maven.plugins/maven-archetype-plugin

getLog().warn( "No Archetype IT projects: root 'projects' directory not found." );
File archetypeFile = project.getArtifact().getFile();
  throw new MojoFailureException( "Unable to get the archetypes' artifact which should have just been built:"
                    + " you probably launched 'mvn archetype:integration-test' instead of"
                    + " 'mvn integration-test'." );
    getLog().warn( "No Archetype IT projects: no directory with goal.txt found." );
  if ( !StringUtils.isEmpty( errors ) )
    throw new MojoExecutionException( errors );
  throw new MojoFailureException( ex, ex.getMessage(), ex.getMessage() );

代码示例来源:origin: jooby-project/jooby

appcp.addAll(resources(mavenProject.getResources()));
Set<Artifact> artifacts = new LinkedHashSet<Artifact>(mavenProject.getArtifacts());
 if (!"pom".equals(artifact.getType())) {
  appcp.add(new File(artifact.getFile().getAbsolutePath()));
watchDirs.add(mavenProject.getBasedir());
watchDirs.addAll(refbasedir);
if (this.watchDirs != null) {
 cmd.setWorkdir(mavenProject.getBasedir());
 getLog().debug("cmd: " + cmd.debug());
  getLog().debug("Starting process: " + cmd.debug());
  cmd.execute();
 } catch (Exception ex) {
  throw new MojoFailureException("Execution of " + cmd + " resulted in error", ex);

代码示例来源:origin: net.flexmojos.oss/flexmojos-maven-plugin

getLog().info( "Skipping RSL creation" );
  return;
getLog().debug( "project.getPackaging = " + packaging );
if ( project.getArtifact().getFile() == null )
  getLog().warn( "Skipping RSL creator, no SWC attached to this project." );
  return;
    throw new MojoExecutionException( e.getMessage(), e );
    throw new MojoFailureException( "Got " + result + " errors building project, check logs" );

代码示例来源:origin: siom79/japicmp

versionRange = VersionRange.createFromVersionSpec(mavenParameters.getVersionRangeWithProjectVersion());
} catch (InvalidVersionSpecificationException e) {
  throw new MojoFailureException("Invalid version versionRange: " + e.getMessage(), e);
  previousArtifact = mavenParameters.getArtifactFactory().createDependencyArtifact(project.getGroupId(), project.getArtifactId(), versionRange, project.getPackaging(), null, Artifact.SCOPE_COMPILE);
  if (!previousArtifact.getVersionRange().isSelectedVersionKnown(previousArtifact)) {
    getLog().debug("Searching for versions in versionRange: " + previousArtifact.getVersionRange());
    List<ArtifactVersion> availableVersions = mavenParameters.getMetadataSource().retrieveAvailableVersions(previousArtifact, mavenParameters.getLocalRepository(), project.getRemoteArtifactRepositories());
    filterSnapshots(availableVersions);
    ArtifactVersion version = versionRange.matchVersion(availableVersions);
    if (version != null) {
      previousArtifact.selectVersion(version.toString());
  throw new MojoFailureException("Invalid comparison version: " + e.getMessage(), e);
} catch (ArtifactMetadataRetrievalException e) {
  throw new MojoExecutionException("Error determining previous version: " + e.getMessage(), e);
if (previousArtifact.getVersion() == null) {
  getLog().info("Unable to find a previous version of the project in the repository.");

代码示例来源:origin: mojohaus/animal-sniffer

private boolean detectJavaBootClasspath( String javaExecutable )
  throws MojoFailureException, MojoExecutionException
  getLog().info( "Attempting to auto-detect the boot classpath for " + javaExecutable );
  Iterator<Artifact> i = pluginArtifacts.iterator();
  Artifact javaBootClasspathDetector = null;
    if ( StringUtils.equals( jbcpdGroupId, candidate.getGroupId() )
      && StringUtils.equals( jbcpdArtifactId, candidate.getArtifactId() ) && candidate.getFile() != null
      && candidate.getFile().isFile() )
      getLog().warn( "Skipping signature generation as could not find boot classpath detector ("
                + ArtifactUtils.versionlessKey( jbcpdGroupId, jbcpdArtifactId ) + ")." );
      return false;
    throw new MojoFailureException( "Could not find boot classpath detector ("
                      + ArtifactUtils.versionlessKey( jbcpdGroupId, jbcpdArtifactId )
                      + ")." );
    throw new MojoExecutionException( e.getLocalizedMessage(), e );

代码示例来源:origin: takari/polyglot-maven

protected Model modelFromNativePom(Log log) throws MojoExecutionException, MojoFailureException {
  Map<String, ModelSource> options = new HashMap<String, ModelSource>();
  options.put(ModelProcessor.SOURCE, new FileModelSource(nativePom));

  assert modelManager != null;
  try {
   ModelReader reader = modelManager.getReaderFor(options);
   if (reader == null) {
    throw new MojoExecutionException("no model reader found for " + nativePom);
   }
   if (log.isDebugEnabled()) {
    log.debug("Parsing native pom " + nativePom);
   }
   return reader.read(nativePom, options);
  } catch (IOException e) {
   throw new MojoFailureException("error parsing " + nativePom, e);
  }
 }
}

代码示例来源:origin: swagger-api/swagger-core

public void execute() throws MojoExecutionException, MojoFailureException
    getLog().info( "Skipping OpenAPI specification resolution" );
    return;
  getLog().info( "Resolving OpenAPI specification.." );
  if (StringUtils.isBlank(encoding)) {
    encoding = projectEncoding;
              openAPIInput = Yaml.mapper().readValue(openapiFileContent, OpenAPI.class);
            } catch (Exception e1) {
              getLog().error( "Error reading/deserializing openapi file" , e);
              throw new MojoFailureException(e.getMessage(), e);
    getLog().error( "Error reading/deserializing openapi file" , e);
    throw new MojoFailureException(e.getMessage(), e);
    getLog().error( "Error resolving API specification" , e);
    throw new MojoFailureException(e.getMessage(), e);
  } catch (IOException e) {
    getLog().error( "Error writing API specification" , e);
    throw new MojoExecutionException("Failed to write API definition", e);
  } catch (Exception e) {
    getLog().error( "Error resolving API specification" , e);
    throw new MojoExecutionException(e.getMessage(), e);

代码示例来源:origin: org.kohsuke/access-modifier-checker

public void execute() throws MojoExecutionException, MojoFailureException {
  if (skip) {
    getLog().info("Skipping access modifier checks");
    return;
    File outputDir = new File(project.getBuild().getOutputDirectory());
    for (Artifact a : (Collection<Artifact>)project.getArtifacts())
      dependencies.add(a.getFile().toURI().toURL());
    URL outputURL = outputDir.toURI().toURL();
    dependencies.add(outputURL);
      String message = "Access modifier checks failed. See the details above";
      if (failOnError) {
        throw new MojoFailureException(message);
      } else {
        getLog().warn(message);
    throw new MojoExecutionException("Failed to enforce @Restricted constraints",e);

代码示例来源:origin: simpligility/android-maven-plugin

getLog().info( deviceLogLinePrefix + "Running tests for specified test package: " + str );
  getLog().info( deviceLogLinePrefix + "Running tests for specified test classes/methods: " 
      + parsedClasses );
getLog().info( deviceLogLinePrefix +  "Running instrumentation tests in " 
    + parsedInstrumentationPackage );
try
  if ( testRunListener.hasFailuresOrErrors() && !testFailSafe )
    throw new MojoFailureException( deviceLogLinePrefix + "Tests failed on device." );
    throw new MojoFailureException( deviceLogLinePrefix + "Test run failed to complete: " 
        + testRunListener.getTestRunFailureCause() );
    throw new MojoFailureException( deviceLogLinePrefix +  testRunListener.getExceptionMessages() );
  throw new MojoExecutionException( deviceLogLinePrefix + "timeout", e );
  throw new MojoExecutionException( deviceLogLinePrefix + "adb command rejected", e );
  throw new MojoExecutionException( deviceLogLinePrefix + "shell command " + "unresponsive", e );

代码示例来源:origin: apache/karaf

private ClassFinder createFinder(String classloaderType) throws Exception {
  ClassFinder finder;
  if ("project".equals(classloaderType)) {
    List<URL> urls = new ArrayList<>();
    urls.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL());
    for (Artifact artifact : project.getArtifacts()) {
      if (artifactInclude != null && artifactInclude.length() > 0 && artifact.getArtifactId().matches(artifactInclude)) {
        File file = artifact.getFile();
        if (file != null) {
          getLog().debug("Use artifact " + artifact.getArtifactId() + ": " + file);
          urls.add(file.toURI().toURL());
        }
      } else {
        getLog().debug("Ignore artifact " + artifact.getArtifactId());
      }
    }
    ClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader());
    finder = new ClassFinder(loader, urls);
  } else if ("plugin".equals(classLoader)) {
    finder = new ClassFinder(getClass().getClassLoader());
  } else {
    throw new MojoFailureException("classLoader attribute must be 'project' or 'plugin'");
  }
  return finder;
}

代码示例来源:origin: appfuse/appfuse

public void execute() throws MojoExecutionException, MojoFailureException {
  if (project.getPackaging().equalsIgnoreCase("pom")) {
    String errorMsg = "[ERROR] This plugin cannot be run from a pom project, please run it from a jar or war project (i.e. core or web).";
    throw new MojoFailureException(errorMsg);
    throw new MojoExecutionException("You must specify an entity name to continue.");
  if (project.getPackaging().equals("war") && (project.hasParent()
    && !project.getParentArtifact().getGroupId().contains("appfuse"))) {
    String moduleName = (String) project.getParent().getModules().get(0);
    getLog().error("[ERROR] No <dao.framework> property found in pom.xml. Please add this property.");

代码示例来源:origin: com.googlecode.maven-download-plugin/download-maven-plugin

/**
 * Will copy the specified artifact into the output directory.
 * @param artifact The artifact already resolved to be copied.
 * @throws MojoFailureException If an error hapen while copying the file.
 */
private void copyFileToDirectory(org.apache.maven.artifact.Artifact artifact) throws MojoFailureException {
  File toCopy = artifact.getFile();
  if (toCopy != null && toCopy.exists() && toCopy.isFile()) {
    try {
      getLog().info("Copying file " + toCopy.getName() + " to directory " + outputDirectory);
      File outputFile = null;
      if (this.outputFileName == null) {
        outputFile = new File(outputDirectory, toCopy.getName());
      } else {
        outputFile = new File(outputDirectory, this.outputFileName);
      }
      Files.copy(toCopy.toPath(), outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
      getLog().debug("Error while copying file", e);
      throw new MojoFailureException("Error copying the file : " + e.getMessage());
    }
  } else {
    throw new MojoFailureException("Artifact file not present : " + toCopy);
  }
}

代码示例来源:origin: apache/drill

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
 if (project == null) {
  throw new MojoExecutionException("This plugin can only be used inside a project.");
  throw new MojoFailureException("can not write to output dir: " + outputPath);
  throw new MojoFailureException("templates not found in dir: " + outputPath);
   project.addCompileSourceRoot(outputPath);
  break;
  case "test":
   project.addTestCompileSourceRoot(outputPath);
  break;
  default:
   throw new MojoFailureException("scope must be compile or test");
  getLog().info(format("Freemarker generation:\n scope: %s,\n config: %s,\n templates: %s",
    scope, config.getAbsolutePath(), templatesPath));
  final File tmp = Files.createTempDirectory("freemarker-tmp").toFile();
   getLog().info("Adding maven data loader");
   settings.setEngineAttribute(MavenDataLoader.MAVEN_DATA_ATTRIBUTE, new MavenData(project));
   settings.add(Settings.NAME_DATA, format("maven: %s()", MavenDataLoader.class.getName()));
  throw new MojoFailureException(MiscUtil.causeMessages(e), e);

代码示例来源:origin: com.microsoft.azure/azure-maven-plugin-lib

@Override
public String assureInputFromUser(String attribute, String defaultValue, String regex, String errorMessage,
                 String prompt) throws MojoFailureException {
  final String initValue = System.getProperty(attribute);
  final String input = StringUtils.isNotEmpty(initValue) ? initValue : defaultValue;
  if (StringUtils.isNotEmpty(input) && validateInputByRegex(input, regex)) {
    log.info(String.format("Use %s for %s", input, attribute));
    return input;
  } else {
    throw new MojoFailureException(String.format("Invalid input for %s : %s", attribute, input));
  }
}

代码示例来源:origin: simpligility/android-maven-plugin

parsedVersionName = project.getVersion();
getLog().info( "Setting " + ATTR_VERSION_NAME + " to " + parsedVersionName );
manifestElement.setAttribute( ATTR_VERSION_NAME, parsedVersionName );
dirty = true;
  || ( parsedVersionCodeAutoIncrement && parsedVersionCodeUpdateFromVersion ) )
throw new MojoFailureException( "versionCodeAutoIncrement, versionCodeUpdateFromVersion and versionCode "
    + "are mutual exclusive. They cannot be specified at the same time. Please specify either "
    + "versionCodeAutoIncrement, versionCodeUpdateFromVersion or versionCode!" );
  getLog().info( "Setting " + ATTR_VERSION_CODE + " to " + parsedVersionCode );
  manifestElement.setAttribute( ATTR_VERSION_CODE, String.valueOf( parsedVersionCode ) );
  dirty = true;
project.getProperties().setProperty( "android.manifest.versionCode", String.valueOf( parsedVersionCode ) );
project.getProperties()
  .setProperty( "android.manifest.applicationIcon", String.valueOf( parsedApplicationIcon ) );
    .equals( parsedSharedUserId, sharedUserIdAttrib.getValue() ) )
  getLog().info( "Setting " + ATTR_SHARED_USER_ID + " to " + parsedSharedUserId );
  manifestElement.setAttribute( ATTR_SHARED_USER_ID, parsedSharedUserId );
  dirty = true;

代码示例来源:origin: square/osstrich

@Override public void execute() throws MojoExecutionException, MojoFailureException {
  String groupId = project.getGroupId();
  String developerConnection = project.getScm().getDeveloperConnection();
  if (!developerConnection.startsWith(SCM_PREFIX)) {
   throw new MojoFailureException("Unexpected developer connection: " + developerConnection);
  }
  String repoUrl = developerConnection.substring(SCM_PREFIX.length());
  File directory = new File(project.getBuild().getDirectory() + "/osstrich");

  JavadocPublisher javadocPublisher =
    new JavadocPublisher(new MavenCentral(), new Cli(), getLog(), directory);

  try {
   int artifactsPublished = javadocPublisher.publishLatest(repoUrl, groupId);
   getLog().info("Published Javadoc for " + artifactsPublished + " artifacts of "
     + groupId + " to " + repoUrl);
  } catch (IOException e) {
   throw new MojoExecutionException(
     "Failed to publish Javadoc of " + groupId + " to " + repoUrl, e);
  }
 }
}

代码示例来源:origin: io.sarl.maven/sarl-maven-plugin

@SuppressWarnings("unchecked")
private void validateDependencyVersions() throws MojoExecutionException, MojoFailureException {
  getLog().info(Messages.CompileMojo_7);
  final String sarlSdkGroupId = this.mavenHelper.getConfig("sarl-sdk.groupId"); //$NON-NLS-1$
  final String sarlSdkArtifactId = this.mavenHelper.getConfig("sarl-sdk.artifactId"); //$NON-NLS-1$
  final Map<String, Artifact> artifacts = this.mavenHelper.getSession().getCurrentProject().getArtifactMap();
  final String sdkArtifactKey = ArtifactUtils.versionlessKey(sarlSdkGroupId, sarlSdkArtifactId);
  final Artifact sdkArtifact = artifacts.get(sdkArtifactKey);
    final Set<Artifact> dependencies = this.mavenHelper.resolveDependencies(sdkArtifactKey, false);
    for (final Artifact dependency : dependencies) {
      final ArtifactVersion dependencyVersion = new DefaultArtifactVersion(dependency.getVersion());
      final String dependencyKey = ArtifactUtils.versionlessKey(dependency);
      final ArtifactVersion currentVersion = versions.get(dependencyKey);
      final Artifact dependencyArtifact = artifacts.get(entry.getKey());
      if (dependencyArtifact != null) {
        final ArtifactVersion dependencyVersion = new DefaultArtifactVersion(dependencyArtifact.getVersion());
        if (entry.getValue().compareTo(dependencyVersion) > 0) {
          final String message = MessageFormat.format(Messages.CompileMojo_8,
              dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId(),
              dependencyArtifact.getVersion(), entry.getValue().toString());
          getLog().error(message);
          hasError = true;
    throw new MojoFailureException(Messages.CompileMojo_10);

相关文章