diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy index 3aac4191e..c3cefa626 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/AbstractServerTask.groovy @@ -25,6 +25,8 @@ import org.apache.commons.io.FileUtils import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.artifacts.Dependency +import org.gradle.api.artifacts.ModuleDependency import org.gradle.api.tasks.bundling.War import org.gradle.api.tasks.Internal import org.gradle.plugins.ear.Ear @@ -982,12 +984,24 @@ abstract class AbstractServerTask extends AbstractLibertyTask { protected List getApplicationFilesFromConfiguration() { List appFiles = new ArrayList() - //This loops all the Dependency objects that get created by the configuration treating them as File objects - //Should also include transitive dependencies - //Can't use the resolved configuration unless we do a check separate from this one, not sure if there is an advantage since we want the applicaitons - project.configurations.libertyApp.each { - if (FilenameUtils.getExtension(it.name).equals('war') || FilenameUtils.getExtension(it.name).equals('ear')) { - appFiles.add(it) + //This loops thorugh all the Dependency objects that get created by the configuration + for (Dependency dep : project.configurations.libertyApp.getDependencies()) { + if (dep instanceof ModuleDependency) { //Check that dep isn't a File dependency + dep.setTransitive(false) //Only want main artifacts, one for Maven and one or more for Gradle/Ivy dependencies + } + + Set depArtifacts = project.configurations.libertyApp.files(dep) //Resolve the artifacts + for (File depArtifact : depArtifacts) { + File appFile = depArtifact + if (dep instanceof ModuleDependency && server.stripVersion && depArtifact.getName().contains(dep.getVersion())) { + String noVersionName = depArtifact.getName().minus("-" + dep.getVersion()) //Assuming default Gradle naming scheme + File noVersionDependencyFile = new File(project.getBuildDir(), 'libs/' + noVersionName) //Copying the file to build/libs with no version + FileUtils.copyFile(depArtifact, noVersionDependencyFile) + appFile = noVersionDependencyFile + } + if (FilenameUtils.getExtension(appFile.getName()).equals('war') || FilenameUtils.getExtension(appFile.getName()).equals('ear')) { + appFiles.add(appFile) + } } } diff --git a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy index bf15a97ab..8f82fe71d 100644 --- a/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy +++ b/src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy @@ -281,14 +281,14 @@ class DevTask extends AbstractServerTask { boolean hotTests, boolean skipTests, String artifactId, int serverStartTimeout, int verifyAppStartTimeout, int appUpdateTimeout, double compileWait, boolean libertyDebug, boolean pollingTest, boolean container, File dockerfile, File dockerBuildContext, - String dockerRunOpts, int dockerBuildTimeout, boolean skipDefaultPorts, boolean keepTempDockerfile, String mavenCacheLocation, File buildFile + String dockerRunOpts, int dockerBuildTimeout, boolean skipDefaultPorts, boolean keepTempDockerfile, String mavenCacheLocation, String packagingType, File buildFile ) throws IOException { super(buildDir, serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, projectDirectory, /* multi module project directory */ projectDirectory, resourceDirs, hotTests, skipTests, false /* skipUTs */, false /* skipITs */, artifactId, serverStartTimeout, verifyAppStartTimeout, appUpdateTimeout, ((long) (compileWait * 1000L)), libertyDebug, true /* useBuildRecompile */, true /* gradle */, pollingTest, container, dockerfile, dockerBuildContext, dockerRunOpts, dockerBuildTimeout, skipDefaultPorts, null /* compileOptions not needed since useBuildRecompile is true */, keepTempDockerfile, mavenCacheLocation, null /* multi module upstream projects */, - false /* recompileDependencies only supported in ci.maven */, getPackagingType(), buildFile, null /* parent build files */ + false /* recompileDependencies only supported in ci.maven */, packagingType, buildFile, null /* parent build files */ ); ServerFeature servUtil = getServerFeatureUtil(); @@ -946,7 +946,7 @@ class DevTask extends AbstractServerTask { resourceDirs, hotTests.booleanValue(), skipTests.booleanValue(), artifactId, serverStartTimeout.intValue(), verifyAppStartTimeout.intValue(), verifyAppStartTimeout.intValue(), compileWait.doubleValue(), libertyDebug.booleanValue(), pollingTest.booleanValue(), container.booleanValue(), dockerfile, dockerBuildContext, dockerRunOpts, - dockerBuildTimeout, skipDefaultPorts.booleanValue(), keepTempDockerfile.booleanValue(), localMavenRepoForFeatureUtility, buildFile + dockerBuildTimeout, skipDefaultPorts.booleanValue(), keepTempDockerfile.booleanValue(), localMavenRepoForFeatureUtility, getPackagingType(), buildFile ); util.addShutdownHook(executor); diff --git a/src/test/groovy/io/openliberty/tools/gradle/LibertyApplicationConfigurationM2DefaultTest.groovy b/src/test/groovy/io/openliberty/tools/gradle/LibertyApplicationConfigurationM2DefaultTest.groovy index efe77bdc1..26937c69c 100644 --- a/src/test/groovy/io/openliberty/tools/gradle/LibertyApplicationConfigurationM2DefaultTest.groovy +++ b/src/test/groovy/io/openliberty/tools/gradle/LibertyApplicationConfigurationM2DefaultTest.groovy @@ -45,7 +45,7 @@ class LibertyApplicationConfigurationM2DefaultTest extends AbstractIntegrationTe @Test public void checkAppInstalled() { - assert new File(buildDir, 'build/wlp/usr/servers/defaultServer/apps/test-maven-war-1.0-SNAPSHOT.war').exists() + assert new File(buildDir, 'build/wlp/usr/servers/defaultServer/apps/test-maven-war.war').exists() } diff --git a/src/test/resources/app-configuration-m2-default-test/appConfigurationM2DefaultTest.gradle b/src/test/resources/app-configuration-m2-default-test/appConfigurationM2DefaultTest.gradle index 84ccdd864..c32f0d570 100644 --- a/src/test/resources/app-configuration-m2-default-test/appConfigurationM2DefaultTest.gradle +++ b/src/test/resources/app-configuration-m2-default-test/appConfigurationM2DefaultTest.gradle @@ -26,6 +26,7 @@ dependencies { liberty { server { + stripVersion = true bootstrapProperties = ['default.http.port': 9080, 'default.https.port': 9443, 'appContext': 'servlet'] diff --git a/src/test/resources/app-configuration-m2-default-test/src/main/liberty/config/server.env b/src/test/resources/app-configuration-m2-default-test/src/main/liberty/config/server.env index 9b8e32a09..b59ba5f48 100644 --- a/src/test/resources/app-configuration-m2-default-test/src/main/liberty/config/server.env +++ b/src/test/resources/app-configuration-m2-default-test/src/main/liberty/config/server.env @@ -1 +1 @@ -APP_LOCATION=test-maven-war-1.0-SNAPSHOT.war \ No newline at end of file +APP_LOCATION=test-maven-war.war \ No newline at end of file