Java Code Examples for org.apache.maven.model.Dependency#setScope()
The following examples show how to use
org.apache.maven.model.Dependency#setScope() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenPomFileGenerator.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private void addDependency(MavenDependencyInternal dependency, String artifactId, String scope, String type, String classifier) { Dependency mavenDependency = new Dependency(); mavenDependency.setGroupId(dependency.getGroupId()); mavenDependency.setArtifactId(artifactId); mavenDependency.setVersion(dependency.getVersion()); mavenDependency.setType(type); mavenDependency.setScope(scope); mavenDependency.setClassifier(classifier); for (ExcludeRule excludeRule : dependency.getExcludeRules()) { Exclusion exclusion = new Exclusion(); exclusion.setGroupId(GUtil.elvis(excludeRule.getGroup(), "*")); exclusion.setArtifactId(GUtil.elvis(excludeRule.getModule(), "*")); mavenDependency.addExclusion(exclusion); } getModel().addDependency(mavenDependency); }
Example 2
Source File: DefaultPomDependenciesConverter.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private Dependency createMavenDependency(ModuleDependency dependency, String name, String type, String scope, String classifier, Set<Configuration> configurations) { Dependency mavenDependency = new Dependency(); mavenDependency.setGroupId(dependency.getGroup()); if (dependency instanceof ProjectDependency) { mavenDependency.setArtifactId(determineProjectDependencyArtifactId((ProjectDependency) dependency)); } else { mavenDependency.setArtifactId(name); } mavenDependency.setVersion(dependency.getVersion()); mavenDependency.setType(type); mavenDependency.setScope(scope); mavenDependency.setOptional(false); mavenDependency.setClassifier(classifier); mavenDependency.setExclusions(getExclusions(dependency, configurations)); return mavenDependency; }
Example 3
Source File: DefaultPomDependenciesConverter.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private Dependency createMavenDependency(ModuleDependency dependency, String name, String type, String scope, String classifier, Set<Configuration> configurations) { Dependency mavenDependency = new Dependency(); mavenDependency.setGroupId(dependency.getGroup()); if (dependency instanceof ProjectDependency) { mavenDependency.setArtifactId(determineProjectDependencyArtifactId((ProjectDependency) dependency)); } else { mavenDependency.setArtifactId(name); } mavenDependency.setVersion(dependency.getVersion()); mavenDependency.setType(type); mavenDependency.setScope(scope); mavenDependency.setOptional(false); mavenDependency.setClassifier(classifier); mavenDependency.setExclusions(getExclusions(dependency, configurations)); return mavenDependency; }
Example 4
Source File: ArtifactUtils.java From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License | 6 votes |
public static void mergeDependencyWithDefaults(Dependency dep, Dependency def) { if (dep.getScope() == null && def.getScope() != null) { dep.setScope(def.getScope()); dep.setSystemPath(def.getSystemPath()); } if (dep.getVersion() == null && def.getVersion() != null) { dep.setVersion(def.getVersion()); } if (dep.getClassifier() == null && def.getClassifier() != null) { dep.setClassifier(def.getClassifier()); } if (dep.getType() == null && def.getType() != null) { dep.setType(def.getType()); } @SuppressWarnings("rawtypes") List exclusions = dep.getExclusions(); if (exclusions == null || exclusions.isEmpty()) { dep.setExclusions(def.getExclusions()); } }
Example 5
Source File: MavenPomFileGenerator.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private void addDependency(MavenDependencyInternal dependency, String artifactId, String scope, String type, String classifier) { Dependency mavenDependency = new Dependency(); mavenDependency.setGroupId(dependency.getGroupId()); mavenDependency.setArtifactId(artifactId); mavenDependency.setVersion(dependency.getVersion()); mavenDependency.setType(type); mavenDependency.setScope(scope); mavenDependency.setClassifier(classifier); for (ExcludeRule excludeRule : dependency.getExcludeRules()) { Exclusion exclusion = new Exclusion(); exclusion.setGroupId(GUtil.elvis(excludeRule.getGroup(), "*")); exclusion.setArtifactId(GUtil.elvis(excludeRule.getModule(), "*")); mavenDependency.addExclusion(exclusion); } getModel().addDependency(mavenDependency); }
Example 6
Source File: AbstractXJC2Mojo.java From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License | 6 votes |
public List<Dependency> getProjectDependencies() { @SuppressWarnings("unchecked") final Set<Artifact> artifacts = getProject().getArtifacts(); if (artifacts == null) { return Collections.emptyList(); } else { final List<Dependency> dependencies = new ArrayList<Dependency>(artifacts.size()); for (Artifact artifact : artifacts) { final Dependency dependency = new Dependency(); dependency.setGroupId(artifact.getGroupId()); dependency.setArtifactId(artifact.getArtifactId()); dependency.setVersion(artifact.getVersion()); dependency.setClassifier(artifact.getClassifier()); dependency.setScope(artifact.getScope()); dependency.setType(artifact.getType()); dependencies.add(dependency); } return dependencies; } }
Example 7
Source File: MavenUtils.java From developer-studio with Apache License 2.0 | 6 votes |
public static Dependency createDependency(String groupId, String artifactId, String version, String scope, String type, String systemPath) { Dependency dependency = new Dependency(); dependency.setGroupId(groupId); dependency.setArtifactId(artifactId); if (version!=null) { dependency.setVersion(version); } if (scope!=null) { dependency.setScope(scope); } if (systemPath!=null) { dependency.setSystemPath(systemPath); } if (type!=null) { dependency.setType(type); } return dependency; }
Example 8
Source File: RawXJC2Mojo.java From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License | 6 votes |
@SuppressWarnings("unchecked") protected void injectDependencyDefaults(Dependency[] dependencies) { if (dependencies != null) { final Map<String, Dependency> dependencyMap = new TreeMap<String, Dependency>(); for (final Dependency dependency : dependencies) { if (dependency.getScope() == null) { dependency.setScope(Artifact.SCOPE_RUNTIME); } dependencyMap.put(dependency.getManagementKey(), dependency); } final DependencyManagement dependencyManagement = getProject().getDependencyManagement(); if (dependencyManagement != null) { merge(dependencyMap, dependencyManagement.getDependencies()); } merge(dependencyMap, getProjectDependencies()); } }
Example 9
Source File: ResolverTest.java From migration-tooling with Apache License 2.0 | 5 votes |
private Dependency getDependency(String coordinates, String scope) { String[] coordinateArray = coordinates.split(":"); Preconditions.checkState(coordinateArray.length == 3); Dependency dependency = new Dependency(); dependency.setGroupId(coordinateArray[0]); dependency.setArtifactId(coordinateArray[1]); dependency.setVersion(coordinateArray[2]); dependency.setScope(scope); return dependency; }
Example 10
Source File: MavenPomFileGenerator.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 5 votes |
private void addDependency(MavenDependencyInternal dependency, String artifactId, String scope, String type, String classifier) { Dependency mavenDependency = new Dependency(); mavenDependency.setGroupId(dependency.getGroupId()); mavenDependency.setArtifactId(artifactId); mavenDependency.setVersion(dependency.getVersion()); mavenDependency.setType(type); mavenDependency.setScope(scope); mavenDependency.setClassifier(classifier); getModel().addDependency(mavenDependency); }
Example 11
Source File: PomGenerator.java From minnal with Apache License 2.0 | 5 votes |
public void addDependency(String groupId, String artifactId, String version, String scope) { Dependency dependency = new Dependency(); dependency.setArtifactId(artifactId); dependency.setGroupId(groupId); dependency.setVersion(version); dependency.setScope(scope); dependenciesToAdd.add(dependency); }
Example 12
Source File: BootstrapMojo.java From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates a dependency artifact from a specification in * {@code groupId:artifactId:version[:type[:classifier]]} format. * * @return artifact object instance. */ private Artifact createDependencyArtifact(String groupId, String artifactId, String version, String type, String classifier) { Dependency dependency = new Dependency(); dependency.setGroupId(groupId); dependency.setArtifactId(artifactId); dependency.setVersion(version); dependency.setType(type); dependency.setClassifier(classifier); dependency.setScope(Artifact.SCOPE_RUNTIME); return repositorySystem.createDependencyArtifact(dependency); }
Example 13
Source File: MavenCoordinatesResolver.java From smart-testing with Apache License 2.0 | 5 votes |
static Dependency createDependencyFromCoordinates(String coordinatesString, boolean excludeTransitive) { final String[] coordinates = coordinatesString.split(":"); int amountOfCoordinates = coordinates.length; if (amountOfCoordinates < 2) { throw new IllegalArgumentException( "Coordinates of the specified strategy [" + coordinatesString + "] doesn't have the correct format."); } final Dependency dependency = new Dependency(); dependency.setGroupId(coordinates[0]); dependency.setArtifactId(coordinates[1]); if (amountOfCoordinates == 3) { dependency.setVersion(coordinates[2]); } else if (amountOfCoordinates >= 4) { dependency.setType(coordinates[2].isEmpty() ? "jar" : coordinates[2]); dependency.setClassifier(coordinates[3]); } if (amountOfCoordinates >= 5) { dependency.setVersion(coordinates[4]); } if (amountOfCoordinates == 6) { dependency.setScope(coordinates[5]); } if (dependency.getVersion() == null || dependency.getVersion().isEmpty()) { dependency.setVersion(ExtensionVersion.version().toString()); } if (excludeTransitive) { Exclusion exclusion = new Exclusion(); exclusion.setGroupId("*"); exclusion.setArtifactId("*"); dependency.setExclusions(Arrays.asList(exclusion)); } return dependency; }
Example 14
Source File: AbstractVersionsDependencyUpdaterMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
protected Artifact toArtifact( Parent model ) throws MojoExecutionException { Dependency d = new Dependency(); d.setArtifactId( model.getArtifactId() ); d.setGroupId( model.getGroupId() ); d.setVersion( model.getVersion() ); d.setType( "pom" ); d.setScope( Artifact.SCOPE_COMPILE ); return this.toArtifact( d ); }
Example 15
Source File: MavenHelper.java From sarl with Apache License 2.0 | 5 votes |
/** Convert an artifact to a dependency. * * @param artifact the artifact to convert. * @return the result of the conversion. */ @SuppressWarnings("static-method") public Dependency toDependency(Artifact artifact) { final Dependency result = new Dependency(); result.setArtifactId(artifact.getArtifactId()); result.setClassifier(artifact.getClassifier()); result.setGroupId(artifact.getGroupId()); result.setOptional(artifact.isOptional()); result.setScope(artifact.getScope()); result.setType(artifact.getType()); result.setVersion(artifact.getVersion()); return result; }
Example 16
Source File: MvnProjectBuilder.java From quarkus with Apache License 2.0 | 5 votes |
public MvnProjectBuilder addDependency(String artifactId, String scope) { final Dependency dep = new Dependency(); dep.setGroupId(DEFAULT_GROUP_ID); dep.setArtifactId(artifactId); dep.setVersion(DEFAULT_VERSION); dep.setScope(scope); return addDependency(dep); }
Example 17
Source File: VertxDependency.java From vertx-maven-plugin with Apache License 2.0 | 5 votes |
public Dependency toDependency() { Dependency dependency = new Dependency(); dependency.setGroupId(groupId); dependency.setArtifactId(artifactId); if (scope != null && !scope.isEmpty()) { dependency.setScope(scope); } if (classifier != null && !classifier.isEmpty()) { dependency.setClassifier(classifier); } return dependency; }
Example 18
Source File: MavenPomFileGenerator.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void addDependency(MavenDependencyInternal dependency, String artifactId, String scope, String type, String classifier) { Dependency mavenDependency = new Dependency(); mavenDependency.setGroupId(dependency.getGroupId()); mavenDependency.setArtifactId(artifactId); mavenDependency.setVersion(dependency.getVersion()); mavenDependency.setType(type); mavenDependency.setScope(scope); mavenDependency.setClassifier(classifier); getModel().addDependency(mavenDependency); }
Example 19
Source File: PomReplaceDependency.java From butterfly with MIT License | 4 votes |
@Override protected TOExecutionResult pomExecution(String relativePomFile, Model model) { TOExecutionResult result = null; String details; Dependency oldDependency = getDependency(model, groupId, artifactId); if (oldDependency != null) { model.removeDependency(oldDependency); Dependency newDependency = new Dependency(); newDependency.setGroupId(newGroupId); newDependency.setArtifactId(newArtifactId); if (newVersion != null) { newDependency.setVersion(newVersion); } if (newScope != null) { newDependency.setScope(newScope); } else { newDependency.setScope(oldDependency.getScope()); } model.addDependency(newDependency); details = String.format("Dependency %s:%s has been replaced by %s:%s in POM file %s", groupId, artifactId, newGroupId, newArtifactId, relativePomFile); result = TOExecutionResult.success(this, details); } else { details = String.format("Dependency %s:%s has not been replaced by %s:%s in POM file %s because it is not present", groupId, artifactId, newGroupId, newArtifactId, relativePomFile); switch (ifNotPresent) { case Warn: result = TOExecutionResult.warning(this, new TransformationOperationException(details)); break; case NoOp: result = TOExecutionResult.noOp(this, details); break; case Fail: // Fail is the default default: result = TOExecutionResult.error(this, new TransformationOperationException(details)); break; } } return result; }
Example 20
Source File: PomHelper.java From versions-maven-plugin with Apache License 2.0 | 4 votes |
/** * Reads imported POMs from the dependency management section. * * @param pom POM * @return a non-null list of {@link Dependency} for each imported POM * @throws XMLStreamException XML stream exception * @see <a href="https://github.com/mojohaus/versions-maven-plugin/issues/134">bug #134</a> * @since 2.4 */ public static List<Dependency> readImportedPOMsFromDependencyManagementSection( ModifiedPomXMLEventReader pom ) throws XMLStreamException { List<Dependency> importedPOMs = new ArrayList<Dependency>(); Stack<String> stack = new Stack<String>(); String groupIdElement = "groupId"; String artifactIdElement = "artifactId"; String versionElement = "version"; String typeElement = "type"; String scopeElement = "scope"; Set<String> recognizedElements = new HashSet<>( Arrays.asList( groupIdElement, artifactIdElement, versionElement, typeElement, scopeElement ) ); Map<String, String> depData = new HashMap<>(); pom.rewind(); String depMgmtDependencyPath = "/project/dependencyManagement/dependencies/dependency"; while ( pom.hasNext() ) { XMLEvent event = pom.nextEvent(); if ( event.isStartElement() ) { final String elementName = event.asStartElement().getName().getLocalPart(); String parent = ""; if ( !stack.isEmpty() ) { parent = stack.peek(); } String currentPath = parent + "/" + elementName; stack.push( currentPath ); if ( currentPath.startsWith( depMgmtDependencyPath ) && recognizedElements.contains( elementName ) ) { final String elementText = pom.getElementText().trim(); depData.put( elementName, elementText ); stack.pop(); } } if ( event.isEndElement() ) { String path = stack.pop(); if ( depMgmtDependencyPath.equals( path ) ) { if ( "pom".equals( depData.get( typeElement ) ) && "import".equals( depData.get( scopeElement ) ) ) { Dependency dependency = new Dependency(); dependency.setGroupId( depData.get( groupIdElement ) ); dependency.setArtifactId( depData.get( artifactIdElement ) ); dependency.setVersion( depData.get( versionElement ) ); dependency.setType( depData.get( typeElement ) ); dependency.setScope( depData.get( scopeElement ) ); importedPOMs.add( dependency ); } depData.clear(); } } } return importedPOMs; }