Java Code Examples for org.apache.maven.model.Dependency#setClassifier()

The following examples show how to use org.apache.maven.model.Dependency#setClassifier() . 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 vote down vote up
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 vote down vote up
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 pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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: DetectExtension.java    From os-maven-plugin with Apache License 2.0 6 votes vote down vote up
private static void interpolate(Map<String, String> dict, Iterable<Dependency> dependencies) {
    if (dependencies == null) {
        return;
    }

    for (Dependency d: dependencies) {
        d.setGroupId(interpolate(dict, d.getGroupId()));
        d.setArtifactId(interpolate(dict, d.getArtifactId()));
        d.setVersion(interpolate(dict, d.getVersion()));
        d.setClassifier(interpolate(dict, d.getClassifier()));
        d.setSystemPath(interpolate(dict, d.getSystemPath()));
        for (Exclusion e: d.getExclusions()) {
            e.setGroupId(interpolate(dict, e.getGroupId()));
            e.setArtifactId(interpolate(dict, e.getArtifactId()));
        }
    }
}
 
Example 5
Source File: MavenPomFileGenerator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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: MojoUtils.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public static Dependency parse(String dependency) {
    Dependency res = new Dependency();
    String[] segments = dependency.split(":");
    if (segments.length >= 2) {
        res.setGroupId(segments[0].toLowerCase());
        res.setArtifactId(segments[1].toLowerCase());
        if (segments.length >= 3 && !segments[2].isEmpty()) {
            res.setVersion(segments[2]);
        }
        if (segments.length >= 4) {
            res.setClassifier(segments[3].toLowerCase());
        }
        return res;
    } else {
        throw new IllegalArgumentException("Invalid dependency description '" + dependency + "'");
    }
}
 
Example 7
Source File: ArtifactUtils.java    From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 8
Source File: DefaultPomDependenciesConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 9
Source File: ExternalBomResolver.java    From sundrio with Apache License 2.0 6 votes vote down vote up
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 10
Source File: GenerateBomMojo.java    From sundrio with Apache License 2.0 5 votes vote down vote up
private static Dependency toDependency(Artifact artifact) {
    Dependency dependency = new Dependency();
    dependency.setGroupId(artifact.getGroupId());
    dependency.setArtifactId(artifact.getArtifactId());
    dependency.setVersion(artifact.getVersion());
    dependency.setType(artifact.getType());
    dependency.setScope(Artifact.SCOPE_COMPILE.equals(artifact.getScope()) ? null : artifact.getScope());
    dependency.setClassifier(artifact.getClassifier());
    dependency.setOptional(artifact.isOptional());
    return dependency;
}
 
Example 11
Source File: MavenPomFileGenerator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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 12
Source File: DependencyToStringTest.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static Dependency createDependency(String gid, String aid, String version, String type, String classifier) {
  Dependency d = new Dependency();
  d.setGroupId(gid);
  d.setArtifactId(aid);
  d.setVersion(version);
  d.setType(type);
  d.setClassifier(classifier);
  return d;
}
 
Example 13
Source File: VertxDependency.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
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 14
Source File: BootstrapMojo.java    From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 15
Source File: MavenCoordinatesResolver.java    From smart-testing with Apache License 2.0 5 votes vote down vote up
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 16
Source File: MavenHelper.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** 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 17
Source File: MavenBuildFile.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@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 18
Source File: Mojo.java    From capsule-maven-plugin with MIT License 5 votes vote down vote up
private Dependency toDependency(final Artifact artifact) {
	if (artifact == null) return null;
	final Dependency dependency = new Dependency();
	dependency.setGroupId(artifact.getGroupId());
	dependency.setArtifactId(artifact.getArtifactId());
	dependency.setVersion(artifact.getVersion());
	dependency.setScope(artifact.getScope());
	dependency.setClassifier(artifact.getClassifier());
	dependency.setOptional(artifact.isOptional());
	if (dependency.getScope() == null || dependency.getScope().isEmpty()) dependency.setScope("compile");
	return dependency;
}
 
Example 19
Source File: VertxDependency.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
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 20
Source File: MavenPomFileGenerator.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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);
}