Reputation: 21
I have made a jar of gradle based Spring boot project, where I have a class:
@Data
@NoArgsConstructor
public class Calculation {
public int multiply(int a, int b)
{
return a*b;
}
}
Then I made a jar
external-0.0.1.jar
Then I try to install it in maven based spring boot project using:
mvnw install:install-file -Dfile=F:\pull\external-0.0.1.jar -DgroupId=com.sakil -DartifactId=external -Dpackaging=jar -Dversion=0.0.1
After that it was added in location:
C:\Users\shahjalal.sakil.m2\repository\com\sakil\external\0.0.1
Then I add it pom.xml:
<dependency>
<groupId>com.sakil</groupId>
<artifactId>external</artifactId>
<version>0.0.1</version>
</dependency>
But when I try to import it :
import com.sakil.external.Calculation;
@SpringBootApplication
public class AcApplication {
public static void main(String[] args) {
SpringApplication.run(AcApplication.class, args);
Calculation cal = new Calculation();
}
Shows Error: package com.sakil.external does not exist
Upvotes: 1
Views: 254
Reputation: 7608
Spring Boot will by default create an executable jar (for running it as a stand-alone application), which is not what you want when creating a library.
To have Spring Boot make a normal jar, add this to your Gradle project:
jar {
enabled = true
}
bootJar {
enabled = false
}
May I also suggest that you use the Maven publishing plugin to upload your library to your local repository? Otherwise, the pom file will not have transitive dependencies included.
Upvotes: 1