简体   繁体   English

javax.inject 不存在

[英]javax.inject does not exists

To investigate troubles with javax.inject I have created minimalistic Gradle project in IntelliJ IDEA.为了调查javax.inject问题,我在 IntelliJ IDEA 中创建了简约的 Gradle 项目。

It contains Main.java only:它只包含Main.java

import javax.inject.Scope;
public class Main {
    public static void main(String[] args) {}
}

build.gradle构建.gradle

buildscript {
    repositories {
        mavenCentral()
    }
}
apply plugin: 'java'
dependencies {
    compileOnly 'javax.annotation:jsr250-api:1.0'
}

and settings.gradle和 settings.gradle

rootProject.name = 'test'

Building the project I got构建我得到的项目

Error:(1, 20) java: package javax.inject does not exist错误:(1, 20) java: 包 javax.inject 不存在

What's wrong with javax, why it doesn't exists?? javax 有什么问题,为什么它不存在??

Hmm, it seems the problem is not specifically with javax.嗯,似乎问题不是专门针对 javax。 Tried to add different dependencies from mavenCentral, no one works.试图从 mavenCentral 添加不同的依赖项,没有人工作。 Like Gradle does not load external libraries at all.就像 Gradle 根本不加载外部库。

Solved解决了

The problem was with repositories - it must be outside of buildscript .问题在于repositories - 它必须在buildscript之外。

只需带上javax.inject依赖

implementation 'javax.inject:javax.inject:1'

Compile only dependencies are distinctly different than regular “compile” dependencies.仅编译依赖项与常规“编译”依赖项明显不同。 They are not included on the runtime classpath and are non-transitive, meaning they are not included in dependent projects.它们不包含在运行时类路径中并且是不可传递的,这意味着它们不包含在依赖项目中。 This is true when using Gradle project dependencies and also when publishing to Maven or Ivy repositories.这在使用 Gradle 项目依赖项以及发布到 Maven 或 Ivy 存储库时都是如此。 In the latter case, compile only dependencies are simply omitted from published metadata.在后一种情况下,仅编译依赖项会从已发布的元数据中简单地省略。

see https://docs.gradle.org/current/userguide/artifact_dependencies_tutorial.htmlhttps://docs.gradle.org/current/userguide/artifact_dependencies_tutorial.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 播放框架:包javax.inject不存在 - Play framework: package javax.inject does not exist 理解 javax.inject 示例代码? - Understanding javax.inject example code? “ NoClassDefFoundError:javax / inject / Provider”即使包含javax.inject依赖项 - “NoClassDefFoundError: javax/inject/Provider” even with javax.inject dependency included 在命令行中使用javac进行编译时出现“package javax.inject不存在”错误 - “package javax.inject does not exist” error while compiling with javac in commandline 为什么Maven 3.3不包含'javax.inject'但是Maven 3.2呢? - Why does Maven 3.3 not include 'javax.inject' but Maven 3.2 does? 用javax.inject替换com.google.inject - Replacing com.google.inject with javax.inject 用于 Micronaut Kotlin 项目的 IntelliJ 中缺少 javax.inject 导入 - javax.inject imports missing in IntelliJ for Micronaut Kotlin project spring 框架中的@Qualifier 和 javax.inject 之间的区别? - Difference between @Qualifier in spring framework and javax.inject? 导入Guava源时无法解析导入javax.inject - The import javax.inject cannot be resolved while import Guava source 我的pom.xml中有javax.inject,会自动弹出吗? - I have javax.inject in my pom.xml, will spring use it automatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM