Dagger leverages JSR 330, the Java standard annotations utilized for dependency injection. These annotations encompass @Inject
, @Singleton
, and more. To integrate this feature, you'll need to include a separate jar file.
For projects employing a build system with integrated dependency management, this inclusion is handled automatically. However, if you're manually managing jar files, you'll need to add it yourself.
To obtain the latest jar, navigate to Maven central: Maven central and scroll to the bottom of the page.
Add to pom.xml:
<dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency>
Adding the Jar File in Java Projects:
For those working with plain Java projects (without Maven, Gradle, or similar tools), you can download a separate Jar file from here.
Once downloaded, add it to your external libraries. In IntelliJ IDEA, follow these steps:
- Select "File" > "Project Structure."
- Navigate to "Libraries" and click the "+" icon to add a new project library.
- Locate the downloaded Jar file and select it.
For Dependency Injection:
implementation "com.google.dagger:dagger:$rootProject.dagger2Version"
Inject via Maven:
- Select "File" > "Project Structure" > "Project Settings" > "Libraries" > "Add" > "From Maven."
- Search for
javax.inject:javax.inject:1
. - Click "OK" once found.
Adding to Gradle:
implementation 'javax.inject:javax.inject:1'
JakartaEE 10 and Above:
In Jakarta EE 10, javax.inject
has moved to the jakarta namespace. To retrieve the Inject
class, use the dependency: https://mvnrepository.com/artifact/jakarta.inject/jakarta.inject-api