我如何决定在.gitignore中添加.idea/jarRepositories.xml [英] How can I decide to add .idea/jarRepositories.xml in .gitignore

查看:121
本文介绍了我如何决定在.gitignore中添加.idea/jarRepositories.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Mac上将Android Studio 3.5.3更新为4.0.1时,发现了一个陌生的文件.idea/jarRepositories.xml.内容如下:

<?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>

上面已经有一个问题 gitignore "rel ="nofollow noreferrer"> github 具有 Android.gitignore ,但在撰写此问题时没有.idea/jarRepositories.xml.

另一方面, Global/JetBrains.gitignore 具有以下评论.

# 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

如您所见,它具有.idea/jarRepositories.xml并且该行已被注释掉.它还具有以下注意事项:

Gradle和Maven自动导入

在将Gradle或Maven与自动导入配合使用时,应排除模块文件, 因为它们将被重新创建,并可能导致流失.如果使用,则取消注释 自动导入.

在Android Studio 4.0.x中,可以在没有自动导入的情况下使用Gradle吗?

远程Jar存储库

在上面的Global/JetBrains.gitignore中,davidkron的拉请求,然后他评论如下:

自IntelliJ 2019.3起,此文件自动出现在我们的git更改中.似乎这些只是有关Maven/Gradle中定义的远程存储库的缓存信息.

进行此更改的原因:

在Maven/Gradle构建中,不应提交自动生成的文件.

指向支持这些规则更改的文档的链接:

我尚未找到有关此文件的文档或文章,但我的假设基于以下步骤:

    在IntelliJ中,远程Jar存储库"可以在设置"菜单中进行管理
  • 我删除了列表中的每个条目->文件消失了
  • 我再次重新导入了Maven/Gradle项目
  • 该文件再次出现,并显示与以前相同的条目

正如他的评论所示,Android Studio 4.0.1具有Remote Jar Repositories设置,如以下屏幕截图所示.

我检查了Android Studio 4.0.0的发行说明,发现 public JpsRemoteRepositoriesConfigurationSerializer() { super("jarRepositories.xml", "RemoteRepositoriesConfiguration"); }

@State(name = "RemoteRepositoriesConfiguration", storages = @Storage("jarRepositories.xml")) public class RemoteRepositoriesConfiguration implements PersistentStateComponent<RemoteRepositoriesConfiguration.State> { // ... }

我还在JetBrain的IntelliJ IDEA社区版资料库中找到了它们的起源.

根据 JPS以前的存储库将自身描述为:

基于Gant的构建框架+ dsl,具有声明性的项目结构定义和自动IntelliJ IDEA项目构建

解决方案

文件.idea/jarRepositories.xml应该添加到.gitignore.它是自动生成的,并且仅包含有关远程的冗余信息. jar存储库.

我们的Android项目在项目级build.gradle中定义了这些存储库,例如:

allprojects {
    repositories {
        google()
        jcenter()
    }
}

第二个参考文献在其网页顶部写了以下介绍:

添加构建依赖项

Android Studio中的Gradle构建系统可轻松将外部二进制文件或其他库模块作为依赖项包含在构建中. ... 本页介绍了如何在Android项目中使用依赖项, ... 但请记住,您的Android项目必须仅使用此页上定义的依赖项配置. [加重]

此外,Android Studio 4.0.1中的添加库依赖项对话框具有以下说明:

第1步.

使用下面的表格找到要添加的库.此表单使用项目的构建文件中指定的存储库(Google,JCenter,Android存储库,Google存储库)

您可以通过以下步骤找到它:

  1. 选择文件> 项目结构... ,位于Android Studio菜单中.
  2. 项目结构对话框的左侧菜单中选择依赖项.
  3. 模块列中选择应用.
  4. 已声明的依赖项列中选择 + .
  5. 在弹出菜单中选择 1库依赖项.

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.

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

解决方案

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()
    }
}

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:

  1. Select File > Project Structure... in the menu of Android Studio.
  2. Select Dependencies in the left-side menu of Project Structure dialog.
  3. Select app in the Modules column.
  4. Select + in the Declared Dependencies column.
  5. Select 1 Library Dependency in the popup menu.

这篇关于我如何决定在.gitignore中添加.idea/jarRepositories.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆