I am migrating from Maven to Gradle and here is a maven execution which i want to implement in gradle:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>3.3.0</version> 
  <executions>
    <execution>
    <id>copy-jar-dependencies</id>
    <phase>prepare-package</phase>
    <goals>
      <goal>copy-dependencies</goal>
      </goals>
      <configuration>
        <outputDirectory>${project.build.outputDirectory}/lib</outputDirectory>                       
        <includeScope>compile</includeScope>                               
    <excludeArtifactIds>${artifact.exclusion.ids}</excludeArtifactIds>
        <excludeGroupIds>${artifact.exclusion.groupids}</excludeGroupIds>
        <excludeTransitive>true</excludeTransitive>
        <stripVersion>false</stripVersion>
    <stripClassifier>true</stripClassifier>                                                     
    <overWriteReleases>true</overWriteReleases>                     
    <overWriteSnapshots>true</overWriteSnapshots>                       
    <overWriteIfNewer>true</overWriteIfNewer>                       
      </configuration>                      
  </execution>
</plugin>   

I created a task named copyJarDependencies as follows:

task copyJarDependencies(type: Copy) {
    from configurations.compileClasspath 
    into "${buildDir}/classes/java/main/lib"
}

But this includes all the dependencies.

I tried the following:

task copyJarDependencies(type: Copy) {
    from(configurations.compileClasspath) {
        exclude group: 'com.github.spullara.mustache.java'
    } 
    into "${buildDir}/classes/java/main/lib"
}

But it gives the following error:

Could not find method exclude() for arguments [{group=com.github.spullara.mustache.java}] on object of type org.gradle.api.internal.file.copy.CopySpecWrapper_Decorated.

Also tried:

task copyJarDependencies(type: Copy, dependsOn: unitTest) {
    from(configurations.compileClasspath) {
        exclude module: 'zap'
    }
    into "${buildDir}/classes/java/main/lib"
}

Even this gives the following error:

Could not find method exclude() for arguments [{module=zap}] on object of type org.gradle.api.internal.file.copy.CopySpecWrapper_Decorated.

How do I exclude the dependencies from getting copied based on groupids and artifact ids and also how do I implement other features such as:

<excludeTransitive>true</excludeTransitive>
<stripVersion>false</stripVersion>
<stripClassifier>true</stripClassifier>                                                     
<overWriteReleases>true</overWriteReleases>                     
<overWriteSnapshots>true</overWriteSnapshots>                       
<overWriteIfNewer>true</overWriteIfNewer>

These are the groupIds and artifactIds i want to exclude:

groupIds:

  1. com.github.spullara.mustache.java
  2. org.apache.logging.log4j
  3. org.jetbrains'

artifactIds:

  1. zap
  2. jython-standalone
  3. start
0

There are 0 best solutions below