Java Code Examples for org.apache.maven.model.Dependency#setGroupId()
The following examples show how to use
org.apache.maven.model.Dependency#setGroupId() .
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: DependencyLoader.java From yaks with Apache License 2.0 | 6 votes |
/** * Construct dependency form coordinate string that follows the format "groupId:artifactId:version". Coordinates must * have a version set. * @param coordinates * @param properties * @param logger * @return */ default Dependency build(String coordinates, Properties properties, Logger logger) throws LifecycleExecutionException { Dependency dependency = new Dependency(); Matcher matcher = COORDINATE_PATTERN.matcher(coordinates); if (!matcher.matches()) { throw new LifecycleExecutionException("Unsupported dependency coordinate. Must be of format groupId:artifactId:version"); } String groupId = matcher.group("groupId"); String artifactId = matcher.group("artifactId"); String version = resolveVersionProperty(matcher.group("version"), properties); dependency.setGroupId(groupId); dependency.setArtifactId(artifactId); dependency.setVersion(version); logger.info(String.format("Add %s", dependency)); return dependency; }
Example 2
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 3
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 4
Source File: ExternalBomResolver.java From sundrio with Apache License 2.0 | 6 votes |
private Dependency toMavenDependency(org.eclipse.aether.graph.Dependency from) { org.eclipse.aether.artifact.Artifact fromArt = from.getArtifact(); Dependency dependency = new Dependency(); dependency.setGroupId(fromArt.getGroupId()); dependency.setArtifactId(fromArt.getArtifactId()); dependency.setVersion(fromArt.getVersion()); dependency.setType(fromArt.getExtension()); dependency.setScope(Artifact.SCOPE_COMPILE.equals(from.getScope()) ? null : from.getScope()); dependency.setClassifier(fromArt.getClassifier()); dependency.setOptional(dependency.isOptional()); if (from.getExclusions() != null && from.getExclusions().size() > 0) { List<Exclusion> exclusions = new LinkedList<Exclusion>(); for (org.eclipse.aether.graph.Exclusion fromEx : from.getExclusions()) { Exclusion ex = new Exclusion(); ex.setGroupId(fromEx.getGroupId()); ex.setArtifactId(fromEx.getArtifactId()); exclusions.add(ex); } dependency.setExclusions(exclusions); } return dependency; }
Example 5
Source File: PomChangePluginTest.java From butterfly with MIT License | 6 votes |
@Test public void addPluginDependencyTest() throws IOException, XmlPullParserException { final Dependency dependency = new Dependency(); dependency.setGroupId("com.test.butterfly"); dependency.setArtifactId("butterfly-transformation"); dependency.setVersion("1.0.0-SNAPSHOT"); List<Dependency> dependencyList = Arrays.asList(dependency); PomChangePlugin uut = new PomChangePlugin("org.codehaus.mojo", "cobertura-maven-plugin").relative("pom.xml").setPluginDependencies(dependencyList); assertTrue(getPluginBeforeChange(uut).getDependencies().isEmpty()); executeAndAssertSuccess(uut); assertEquals(getPluginAfterChange(uut).getDependencies().size(), dependencyList.size()); assertEquals(getPluginAfterChange(uut).getDependencies().get(0).getArtifactId(), dependency.getArtifactId()); assertEquals(getPluginAfterChange(uut).getDependencies().get(0).getGroupId(), dependency.getGroupId()); assertEquals(getPluginAfterChange(uut).getDependencies().get(0).getVersion(), dependency.getVersion()); }
Example 6
Source File: DependencyFilterTest.java From dropwizard-debpkg-maven-plugin with Apache License 2.0 | 5 votes |
private static Dependency createDependency(String groupId, String artifactId, String version) { final Dependency dependency = new Dependency(); dependency.setGroupId(groupId); dependency.setArtifactId(artifactId); dependency.setVersion(version); return dependency; }
Example 7
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 8
Source File: QuarkusTestPlatformDescriptorLoader.java From quarkus with Apache License 2.0 | 5 votes |
public static void addExtension(String groupId, String artifactId, String version, String name, String guide, List<Extension> extensions, List<Dependency> bomDeps) { extensions.add(new Extension(groupId, artifactId, version).setName(name).setGuide(guide)); final Dependency d = new Dependency(); d.setGroupId(groupId); d.setArtifactId(artifactId); d.setVersion(version); bomDeps.add(d); }
Example 9
Source File: DependencyAddedInProfileTest.java From quarkus with Apache License 2.0 | 5 votes |
@Override protected TsArtifact modelApp() { final TsQuarkusExt extA_100 = new TsQuarkusExt("ext-a", "1.0.0"); addToExpectedLib(extA_100.getRuntime()); final TsQuarkusExt extB_100 = new TsQuarkusExt("ext-b", "1.0.0"); install(extB_100); final TsArtifact extB_100_rt = extB_100.getRuntime(); addToExpectedLib(extB_100_rt); final TsArtifact appJar = TsArtifact.jar("app") .addDependency(extA_100); final Profile profile = new Profile(); profile.setId("extra"); Activation activation = new Activation(); ActivationProperty ap = new ActivationProperty(); ap.setName("extra"); activation.setProperty(ap); profile.setActivation(activation); final Dependency dep = new Dependency(); dep.setGroupId(extB_100_rt.getGroupId()); dep.setArtifactId(extB_100_rt.getArtifactId()); dep.setVersion(extB_100_rt.getVersion()); profile.addDependency(dep); appJar.addProfile(profile); createWorkspace(); setSystemProperty("extra", "extra"); return appJar; }
Example 10
Source File: MavenBuildFile.java From quarkus with Apache License 2.0 | 5 votes |
@Override protected void addDependencyInBuildFile(AppArtifactCoords coords) throws IOException { if (getModel() != null) { final Dependency d = new Dependency(); d.setGroupId(coords.getGroupId()); d.setArtifactId(coords.getArtifactId()); d.setVersion(coords.getVersion()); // When classifier is empty, you get <classifier></classifier> in the pom.xml if (coords.getClassifier() != null && !coords.getClassifier().isEmpty()) { d.setClassifier(coords.getClassifier()); } d.setType(coords.getType()); getModel().addDependency(d); } }
Example 11
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 12
Source File: AddExtensionIT.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testAddExtensionWithASingleExtensionWithPluralForm() throws MavenInvocationException, IOException { testDir = initProject(PROJECT_SOURCE_DIR, "projects/testAddExtensionWithASingleExtensionWithPluralForm"); invoker = initInvoker(testDir); addExtension(true, VERTX_ARTIFACT_ID); Model model = loadPom(testDir); Dependency expected = new Dependency(); expected.setGroupId(QUARKUS_GROUPID); expected.setArtifactId(VERTX_ARTIFACT_ID); assertThat(contains(model.getDependencies(), expected)).isTrue(); }
Example 13
Source File: LocalWorkspaceDiscoveryTest.java From quarkus with Apache License 2.0 | 5 votes |
private static Dependency newDependency(String groupId, String artifactId, String version) { final Dependency dep = new Dependency(); dep.setGroupId(groupId); dep.setArtifactId(artifactId); dep.setVersion(version); return dep; }
Example 14
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 15
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 16
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 17
Source File: MavenHelper.java From microprofile-starter with Apache License 2.0 | 5 votes |
public void addDependency(Model pomFile, String groupId, String artifactId, String version, String scope, String type) { Dependency dependency = new Dependency(); dependency.setGroupId(groupId); dependency.setArtifactId(artifactId); dependency.setVersion(version); if (scope != null) { dependency.setScope(scope); } if (type != null) { dependency.setType(type); } pomFile.addDependency(dependency); }
Example 18
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; }
Example 19
Source File: DataflowDependencyManagerTest.java From google-cloud-eclipse with Apache License 2.0 | 4 votes |
private static Dependency dataflowDependency() { Dependency dependency = new Dependency(); dependency.setArtifactId("google-cloud-dataflow-java-sdk-all"); dependency.setGroupId("com.google.cloud.dataflow"); return dependency; }
Example 20
Source File: MavenUtils.java From developer-studio with Apache License 2.0 | 4 votes |
public static void updateDependecyList(IProject project, MavenProject mavenProject) throws Exception { List<Dependency> existingDependencies = mavenProject.getModel().getDependencies(); // List<String> newDependencyStrings=new ArrayList<String>(); // List<String> existingDependencyStrings=new ArrayList<String>(); List<Dependency> newDependencyList = new ArrayList<Dependency>(); Map<String, JavaLibraryBean> dependencyInfoMap = JavaLibraryUtil.getDependencyInfoMap(project); Map<String, String> map = ProjectDependencyConstants.DEPENDENCY_MAP; for (JavaLibraryBean bean : dependencyInfoMap.values()) { if (bean.getVersion().contains("${")){ for(String path: map.keySet()) { bean.setVersion(bean.getVersion().replace(path, map.get(path))); } } Dependency dependency = new Dependency(); dependency.setArtifactId(bean.getArtifactId()); dependency.setGroupId(bean.getGroupId()); dependency.setVersion(bean.getVersion()); // String dependencyString = getDependencyString(dependency); // newDependencyStrings.add(dependencyString); newDependencyList.add(dependency); // if(!dependencies.contains(dependency)){ // dependencies.add(dependency); // } } // for (Dependency dependency : existingDependencies) { // String dependencyString = getDependencyString(dependency); // existingDependencyStrings.add(dependencyString); // } for (Dependency newDependency : newDependencyList) { boolean found=false; for (Dependency existingDependency : existingDependencies) { if(newDependency.getArtifactId().equals(existingDependency.getArtifactId()) && newDependency.getGroupId().equals(existingDependency.getGroupId()) && newDependency.getVersion().equals(existingDependency.getVersion())){ found = true; } } if(!found){ existingDependencies.add(newDependency); } } // for (Dependency dependency : newDependencyList) { // String dependencyString = getDependencyString(dependency); // if (!newDependencyStrings.contains(dependencyString)){ // existingDependencies.add(dependency); // } // } addMavenDependency(mavenProject, existingDependencies); }