8

I am trying to convert my Gradle project to Maven using Maven plugin. I am following this SO link but when I ran the Gradle install command I got the following error

C:\Users\>gradle install

FAILURE: Build failed with an exception.

* What went wrong:
Task 'install' not found in root project .

* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log outpu

* Get more help at https://help.gradle.org

BUILD FAILED in 0s

When I did gradle -tasks it is not showing install. what to do in this?

Rudy Vissers
  • 5,267
  • 4
  • 35
  • 37
LowCool
  • 1,187
  • 5
  • 25
  • 51

2 Answers2

5

Did you maybe mean gradle init as described at https://docs.gradle.org/current/userguide/build_init_plugin.html?

The install task is added by the maven plugin if you apply it to your build which you didn't do. It installs the built artefact to your local maven repository. That is not what you want in your situation. Anyway I'd recommend using the maven-publish plugin instead of the maven plugin.

Vampire
  • 35,631
  • 4
  • 76
  • 102
5

If you add apply plugin: 'maven' the gradle install creates a POM.

Gradle script is this.

buildscript {
     repositories {
         maven { url "http://repo.spring.io/snapshot" }
         maven { url "http://repo.spring.io/milestone" }
         maven { url "https://repo1.maven.org/maven2/" }
         mavenLocal()
        mavenCentral()

    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: "org.springframework.boot"
apply plugin: 'io.spring.dependency-management'
jar {
    baseName = 'Angular-Boot-Rest'
    version =  '0.1.0'
}

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "http://repo.spring.io/libs-release" }
}


tasks.withType(Copy) {
    eachFile { println it.file }
}
jar {
    enabled = true
}
dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("junit:junit")
} 

task stage(dependsOn: ['clean','build','jar', 'installApp']){}

POM created is this.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId/>
  <artifactId>Angular-Boot-Rest</artifactId>
  <version>unspecified</version>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <artifactId>tomcat-annotations-api</artifactId>
          <groupId>org.apache.tomcat</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.0.5.RELEASE</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>
Mohan Radhakrishnan
  • 3,002
  • 5
  • 28
  • 42
  • 2
    Thanks for this. It looks like gradle removed maven plugin with gradle 7. There is a new plugin called maven-publish. More detail here: https://docs.gradle.org/7.0/userguide/upgrading_version_6.html?_ga=2.36206368.1811891725.1642614013-1790628645.1642007601#removal_of_the_legacy_maven_plugin – Hodglem Jan 19 '22 at 18:34