mirror of https://github.com/apache/maven.git
[MNG-4173] Remove automatic version resolution for POM plugins
o Reduced validation error to warning because this change seems to cause troubles for many projects out there o Extended lifecylce executor to take care of non-versioned plugins git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@790202 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
22516c9fa7
commit
512d83070a
|
@ -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<ArtifactRepository> 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<ArtifactRepository> 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() )
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue