我知道注释用于修改代码而不实际是代码,例如:
@Author(
name = "Benjamin Franklin",
date = "3/27/2003"
)
Run Code Online (Sandbox Code Playgroud)
但我不明白如何使用注释比只说 name = "Benjamin Franklin" 更好/更清晰/更简洁?添加注解如何加强代码?
编辑:对不起,另一个问题,但我知道@Override 可以帮助防止/跟踪调用方法或类时的拼写错误,但它是如何做到的?它对实际程序有帮助吗?
我是gradle的新手,但遇到了我不太了解的构建错误。我的项目只是一个空外壳,具有目录结构,没有Java源代码。这是我的根build.gradle文件
allprojects {
//Put instructions for all projects
task hello << { task -> println "I'm $task.project.name" }
}
subprojects {
//Put instructions for each sub project
apply plugin: "java"
repositories {
mavenCentral()
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Run Code Online (Sandbox Code Playgroud)
当我执行gradle build命令时,构建失败,因为它不知道此消息的testCompile方法:
在根项目上找不到参数[{group = junit,name = junit,version = 4. +}]的方法testCompile()
我使用Gradle 2.5。
我知道,此方法是我已加载的java插件的一部分。我看不出出了什么问题,您能帮忙吗?谢谢 !
我有混合Java和Kotlin中,我想从运行演示项目的代码command line。仅对于 java,我可以运行该程序,java -jar foo.jar但是当我使用Kotlin代码中的任何类时,它会生成java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
我尝试了不同的解决方案并检查了jar文件。它包含这两个类,但我想kotlin-runtimejar 中缺少它。
这是build.gradle文件
plugins {
id 'java-library'
id 'org.jetbrains.kotlin.jvm'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
test.java.srcDirs += 'src/test/kotlin/'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation 'junit:junit:4.12'
}
jar {
manifest {
attributes 'Main-Class': 'com.mallaudin.App'
}
from {
configurations.compile.collect {
it.isDirectory()? it: zipTree(it)
}
}
}
Run Code Online (Sandbox Code Playgroud)
生成jar文件的内容
.
??? com
? ??? mallaudin
? ??? App.class …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习 spark java web 框架。我正在使用 Intellij 并创建了一个新项目,刚刚添加了一个 HelloWorld 类,但是出现了这个错误,
Build file '/Users/mingwang/SourceCodes/spark-example/build.gradle' line: 17
A problem occurred evaluating root project 'spark-example'.
> Could not find method compile() for arguments [com.sparkjava:spark-core:2.9.3] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Run Code Online (Sandbox Code Playgroud)
我的 build.gradle 就像
plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '7.0.0'
}
group 'org.example' …Run Code Online (Sandbox Code Playgroud) 我正在尝试向Android Studio中的现有项目添加导航菜单.但是,按照官方网站上的说明,我<android.support.v4.widget.DrawerLayout ...在我的视图的其余部分添加了一个标记,并在主要活动布局的主ConstraintLayout下,我将示例导航绘制放在其下面:
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/my_navigation_items" />
Run Code Online (Sandbox Code Playgroud)
最后一行在构建时会导致一些问题:
Error:error: attribute 'com. ... :menu' not found.
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么会这样.所述app的部分app:menu中的DrawerLayout标签中定义为:xmlns:app="http://schemas.android.com/apk/res-auto"
这似乎也会导致Cannot resolve symbol R我的MainActivity.java文件中出现错误.
无论如何,非常感谢任何帮助!
我将Android Studio从3.0.1更新为3.1.0
但是在更新后,当我构建项目时,它显示2警告:
1.将编译替换为实现(编译支持将于2018年底终止)
2.用testImplementaion替换testCompile(并且testCompile支持将在2018年底终止)
因此,最后进行这些更改,但是之后,它显示了一些错误:
build.gradle(模块:应用)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "biz.coolpage.aashish.app"
minSdkVersion 17
targetSdkVersion 27
versionCode 4
versionName "1.2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:design:27.1.0'
implementation project(':library')
}
Run Code Online (Sandbox Code Playgroud)
build.gradle(Project:Abc)
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
allprojects {
repositories {
jcenter() …Run Code Online (Sandbox Code Playgroud) java ×5
gradle ×3
android ×2
annotations ×1
command-line ×1
compilation ×1
drawerlayout ×1
javacompiler ×1
kotlin ×1
spark-java ×1
updates ×1
xml ×1