diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 785ead393f..5463c785df 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -630,90 +630,98 @@ public class DefaultLifecycleExecutor // if ( plugin.getVersion() == null ) { - File artifactMetadataFile; - - String localPath; - - // Search in the local repositiory for a version - // - // maven-metadata-local.xml - // - localPath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata-" + session.getLocalRepository().getId() + ".xml"; - - artifactMetadataFile = new File( session.getLocalRepository().getBasedir(), localPath ); - - if ( !artifactMetadataFile.exists() /* || user requests snapshot updates */ ) - { - // Search in remote repositories for a version. - // - // maven-metadata-{central|nexus|...}.xml - // - //TODO: we should cycle through the repositories but take the repository which actually - // satisfied the prefix. - for ( ArtifactRepository repository : project.getPluginArtifactRepositories() ) - { - localPath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata-" + repository.getId() + ".xml"; - - artifactMetadataFile = new File( session.getLocalRepository().getBasedir(), localPath ); - - if ( !artifactMetadataFile.exists() ) - { - try - { - String remotePath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata.xml"; - - repositorySystem.retrieve( repository, artifactMetadataFile, remotePath, session.getRequest().getTransferListener() ); - } - catch ( TransferFailedException e ) - { - continue; - } - catch ( ResourceDoesNotExistException e ) - { - continue; - } - } - - break; - } - } - - if ( artifactMetadataFile.exists() ) - { - try - { - Metadata pluginMetadata = readMetadata( artifactMetadataFile ); - - String release = pluginMetadata.getVersioning().getRelease(); - - if ( release != null ) - { - plugin.setVersion( release ); - } - else - { - String latest = pluginMetadata.getVersioning().getLatest(); - - if ( latest != null ) - { - plugin.setVersion( latest ); - } - } - } - catch ( RepositoryMetadataReadException e ) - { - logger.warn( "Error reading plugin metadata: ", e ); - } - } - else - { - throw new PluginNotFoundException( plugin, null ); - } + resolvePluginVersion( plugin, session.getLocalRepository(), project.getPluginArtifactRepositories() ); } return pluginManager.getMojoDescriptor( plugin, goal, session.getLocalRepository(), project.getPluginArtifactRepositories() ); } + private void resolvePluginVersion( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) + throws PluginNotFoundException + { + File artifactMetadataFile = null; + + String localPath; + + // Search in remote repositories for a (released) version. + // + // maven-metadata-{central|nexus|...}.xml + // + //TODO: we should cycle through the repositories but take the repository which actually + // satisfied the prefix. + for ( ArtifactRepository repository : remoteRepositories ) + { + localPath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata-" + repository.getId() + ".xml"; + + artifactMetadataFile = new File( localRepository.getBasedir(), localPath ); + + if ( !artifactMetadataFile.exists() /* || user requests snapshot updates */) + { + try + { + String remotePath = plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata.xml"; + + repositorySystem.retrieve( repository, artifactMetadataFile, remotePath, null ); + } + catch ( TransferFailedException e ) + { + continue; + } + catch ( ResourceDoesNotExistException e ) + { + continue; + } + } + + break; + } + + // Search in the local repositiory for a (development) version + // + // maven-metadata-local.xml + // + if ( artifactMetadataFile == null || !artifactMetadataFile.exists() ) + { + localPath = + plugin.getGroupId().replace( '.', '/' ) + "/" + plugin.getArtifactId() + "/maven-metadata-" + + localRepository.getId() + ".xml"; + + artifactMetadataFile = new File( localRepository.getBasedir(), localPath ); + } + + if ( artifactMetadataFile.exists() ) + { + try + { + Metadata pluginMetadata = readMetadata( artifactMetadataFile ); + + String release = pluginMetadata.getVersioning().getRelease(); + + if ( release != null ) + { + plugin.setVersion( release ); + } + else + { + String latest = pluginMetadata.getVersioning().getLatest(); + + if ( latest != null ) + { + plugin.setVersion( latest ); + } + } + } + catch ( RepositoryMetadataReadException e ) + { + logger.warn( "Error reading plugin metadata: ", e ); + } + } + else + { + throw new PluginNotFoundException( plugin, null ); + } + } + private void injectPluginDeclarationFromProject( Plugin plugin, MavenProject project ) { Plugin pluginInPom = findPlugin( plugin, project.getBuildPlugins() ); @@ -857,6 +865,18 @@ public class DefaultLifecycleExecutor private void populateDefaultConfigurationForPlugin( Plugin plugin, ArtifactRepository localRepository, List remoteRepositories ) throws LifecycleExecutionException { + if ( plugin.getVersion() == null ) + { + try + { + resolvePluginVersion( plugin, localRepository, remoteRepositories ); + } + catch ( PluginNotFoundException e ) + { + throw new LifecycleExecutionException( "Error resolving version for plugin " + plugin, e ); + } + } + for( PluginExecution pluginExecution : plugin.getExecutions() ) { for( String goal : pluginExecution.getGoals() ) diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index d9f89aba5a..b5b7e01909 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -36,6 +36,7 @@ import org.apache.maven.model.ModelBuilder; import org.apache.maven.model.ModelBuildingException; import org.apache.maven.model.ModelBuildingRequest; import org.apache.maven.model.ModelBuildingResult; +import org.apache.maven.model.ModelProblem; import org.apache.maven.model.Profile; import org.apache.maven.model.UrlModelSource; import org.apache.maven.model.resolution.ModelResolver; @@ -102,6 +103,17 @@ public class DefaultProjectBuilder throw new ProjectBuildingException( "[unknown]", "Failed to build project for " + pomFile, pomFile, e ); } + if ( localProject && !result.getProblems().isEmpty() && logger.isWarnEnabled() ) + { + logger.warn( "One or more problems were encoutered while building the effective model:" ); + for ( ModelProblem problem : result.getProblems() ) + { + logger.warn( problem.getMessage() ); + } + logger.warn( "It is highly recommended to fix these problems" + + ", otherwise the project will fail to build with future Maven versions." ); + } + Model model = result.getEffectiveModel(); File parentPomFile = result.getRawModel( result.getModelIds().get( 1 ) ).getPomFile(); diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java index 0be650e33a..77662f9cd3 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java @@ -219,7 +219,7 @@ public class DefaultModelValidator validateStringNotEmpty( "build.plugins.plugin.groupId", result, false, p.getGroupId() ); - validateStringNotEmpty( "build.plugins.plugin.version", result, false, p.getVersion(), p.getKey() ); + validateStringNotEmpty( "build.plugins.plugin.version", result, true, p.getVersion(), p.getKey() ); } validateResources( result, build.getResources(), "build.resources.resource" ); @@ -236,7 +236,7 @@ public class DefaultModelValidator validateStringNotEmpty( "reporting.plugins.plugin.groupId", result,false, p.getGroupId() ); - validateStringNotEmpty( "reporting.plugins.plugin.version", result, false, p.getVersion(), p.getKey() ); + validateStringNotEmpty( "reporting.plugins.plugin.version", result, true, p.getVersion(), p.getKey() ); } } diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java index c51179f2c5..afa4998898 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -240,10 +240,10 @@ public class DefaultModelValidatorTest { ModelValidationResult result = validate( "missing-plugin-version-pom.xml" ); - assertEquals( 1, result.getErrors().size() ); + assertEquals( 1, result.getWarnings().size() ); assertEquals( "'build.plugins.plugin.version' is missing for org.apache.maven.plugins:maven-it-plugin", - result.getErrors().get( 0 ) ); + result.getWarnings().get( 0 ) ); } public void testMissingRepositoryId()