问题
I found an unfamiliar file .idea/jarRepositories.xml
, when I updated Android Studio 3.5.3
to 4.0.1
on Mac. The content is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
</component>
</project>
There is already a question on it, and VonC answered that it can be added to .gitignore
.
I was wondering if I should add it in .gitignore
and shouldn't commit it to git. How can I decide to add it to .gitignore
?
JetBrains.gitignore
The popular repository gitignore of github has Android.gitignore, but it has no .idea/jarRepositories.xml
at the time of writing this question.
On the other hand, Global/JetBrains.gitignore has the following comments.
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
As you can see, it has .idea/jarRepositories.xml
and the line is commented out. It also has the following notes:
Gradle and Maven with auto-import
When using Gradle or Maven with auto-import, you should exclude module files, since they will be recreated, and may cause churn. Uncomment if using auto-import.
In Android Studio 4.0.x
, is it possible to use Gradle without auto-import?
Remote Jar Repositories
In the above Global/JetBrains.gitignore
, the line # .idea/jarRepositories.xml
has been added by davidkron's pull request, and he commented as follows:
Since IntelliJ 2019.3 this file appeared automatically in our git changes. It seems these are just cached information about remote repositories that are defined in Maven/Gradle.
Reasons for making this change:
In a Maven/Gradle build, automatically generated files should should not be commited.
Links to documentation supporting these rule changes:
I haven't found a documentation or article about this file, but I'm basing my assumption on the following steps:
- in IntelliJ the "Remote Jar Repositories" can be managed in the Settings menu
- I deleted every entry in the list -> file disappeared
- I re-imported the Maven/Gradle project again
- the file appeared again with the same entries present as before
As his comment, Android Studio 4.0.1
has Remote Jar Repositories
settings, as you can see in the following screen shot.
I checked the release notes of Android Studio 4.0.0
, and found a section as follows:
IntelliJ IDEA 2019.3.3
The core Android Studio IDE has been updated with improvements from IntelliJ IDEA through the 2019.3.3 release.
To learn more about the improvements from other IntelliJ versions that are included cumulatively with version 2019.3.3, see the following pages:
- IntelliJ IDEA 2019.3
- IntelliJ IDEA 2019.3.3
I'm not sure but was wondering if I should add .idea/jarRepositories.xml
in .gitignore
and shouldn't commit it to git. How can I decide to add it or not? I really appreciate it if someone could clarify the criteria.
Update:
In the source code of Android Studio 4.0.0
, I found source files, which define the file name jarRepositories.xml
:
JpsRemoteRepositoriesConfigurationSerializer.java
public JpsRemoteRepositoriesConfigurationSerializer() {
super("jarRepositories.xml", "RemoteRepositoriesConfiguration");
}
RemoteRepositoriesConfiguration.java
@State(name = "RemoteRepositoriesConfiguration", storages = @Storage("jarRepositories.xml"))
public class RemoteRepositoriesConfiguration implements PersistentStateComponent<RemoteRepositoriesConfiguration.State> {
// ...
}
I also found their origins in the repository of JetBrain's IntelliJ IDEA Community Edition.
- JpsRemoteRepositoriesConfigurationSerializer.java
- RemoteRepositoriesConfiguration.java
Jps
stands for JetBrains Project System, according to a document:
The project model in External Build process is provided by JPS (JetBrains Project System).
JPS's previous repository describes itself as:
Gant based build framework + dsl, with declarative project structure definition and automatic IntelliJ IDEA projects build
回答1:
The file .idea/jarRepositories.xml
should be added to .gitignore
. It is auto-generated and has only redundant information about remote jar repositories.
Our Android projects define those repositories in the project-level build.gradle
such as:
allprojects {
repositories {
google()
jcenter()
}
}
- https://developer.android.com/studio/build#top-level
- https://developer.android.com/studio/build/dependencies.html#remote-repositories
- https://docs.gradle.org/current/userguide/dependency_management.html#declaring-repositories
The second reference wrote the following introduction at the top of its webpage:
Add build dependencies
The Gradle build system in Android Studio makes it easy to include external binaries or other library modules to your build as dependencies. ... This page describes how to use dependencies with your Android project, ... but remember that your Android project must use only the dependency configurations defined on this page. [emphasis added]
Also, Add Library Dependencies dialog in Android Studio 4.0.1
has an instruction like this:
Step 1.
Use the form below to find the library to add. This form uses the repositories specified in the project's build files (Google, JCenter, Android Repository, Google Repository)
You can find it with the following steps:
- Select File > Project Structure... in the menu of Android Studio.
- Select Dependencies in the left-side menu of Project Structure dialog.
- Select app in the Modules column.
- Select + in the Declared Dependencies column.
- Select 1 Library Dependency in the popup menu.
回答2:
How can I decide to add it or not?
A clear general criteria to decide if you should ignore a file is:
Can you clone the repository without that file and still have a valid project (one you can compile and execute)
For example, if that file is automatically regenerated, or re-created with custom local paths (which would not make sense for a different developer on a different PC), then that file can be ignored.
So try it out, especially considering you can "disable or enable Gradle / Maven auto-import for an IntelliJ IDEA project".
来源:https://stackoverflow.com/questions/63342780/how-can-i-decide-to-add-idea-jarrepositories-xml-in-gitignore