프로젝트 설정settings 페이지에서 확인할 수 있는 스크립트 ID를 해당 사용자에게 제공합니다.
권장사항
라이브러리를 작성할 때 따라야 할 가이드라인은 다음과 같습니다.
프로젝트는 다른 사용자가 라이브러리를 포함할 때 기본 식별자로 사용되므로 프로젝트에 의미 있는 이름을 선택하세요.
스크립트의 하나 이상의 메서드가 라이브러리 사용자에게 표시되지 않도록 하려면 메서드 이름을 밑줄로 끝내면 됩니다. 예를 들면 myPrivateMethod_()입니다.
열거 가능한 전역 속성만 라이브러리 사용자에게 표시됩니다. 여기에는 함수 선언, var를 사용하여 함수 외부에서 생성된 변수, 전역 객체에 명시적으로 설정된 속성이 포함됩니다. 예를 들어 enumerable이 false로 설정된 Object.defineProperty()는 라이브러리에서 사용할 수 있는 기호를 만들지만 이 기호는 사용자가 액세스할 수 없습니다.
라이브러리 사용자가 스크립트 에디터 자동 완성 및 자동 생성된 문서를 사용하려면 모든 함수에 JSDoc 스타일 문서가 있어야 합니다. 예를 들면 다음과 같습니다.
라이브러리로 작업할 때는 공유 리소스와 비공유 리소스라는 두 가지 유형의 리소스가 있습니다. 공유 리소스는 라이브러리와 포함 스크립트 모두 동일한 리소스 인스턴스에 대한 액세스 권한이 내장되어 있음을 의미합니다. 다음 다이어그램은 사용자 속성의 예를 사용하여 공유 리소스를 보여줍니다.
공유되지 않은 리소스는 라이브러리와 포함 스크립트 모두 리소스의 인스턴스에만 내장 액세스 권한이 있음을 의미합니다. 하지만 라이브러리는 공유되지 않은 리소스에서 작동하는 명시적 함수를 사용하여 리소스에 대한 액세스를 제공할 수 있습니다. 다음은 스크립트 속성을 노출하기 위해 라이브러리에 포함할 함수의 예입니다.
* 즉, 라이브러리에는 기능/리소스의 자체 인스턴스가 없으며 대신 이를 호출한 스크립트에서 생성된 인스턴스를 사용합니다. ** 즉, 라이브러리에는 리소스/기능의 자체 인스턴스가 있으며 라이브러리를 사용하는 모든 스크립트는 동일한 인스턴스를 공유하고 액세스할 수 있습니다.
라이브러리 테스트
라이브러리를 테스트하려면 헤드 배포를 사용하세요. 스크립트에 편집자 수준 액세스 권한이 있는 사용자는 누구나 최신 배포를 사용할 수 있습니다.
라이브러리 디버그
라이브러리가 포함된 프로젝트에서 디버거를 사용하면 포함된 라이브러리의 함수로 단계별로 이동할 수 있습니다. 코드가 보기 전용 모드에서 올바른 버전으로 디버거에 표시됩니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-04(UTC)"],[[["\u003cp\u003eLibraries in Apps Script enable code reuse across different scripts but can impact execution speed, especially in UI-heavy applications or add-ons.\u003c/p\u003e\n"],["\u003cp\u003eTo use a library, you need its Script ID and at least view-level access, then add it to your project specifying the version and identifier.\u003c/p\u003e\n"],["\u003cp\u003eLibraries are accessed like built-in services; use the identifier followed by a period to view available methods.\u003c/p\u003e\n"],["\u003cp\u003eWhen creating a library, use meaningful names, consider visibility of methods (using underscores for private ones), and provide JSDoc documentation for user-facing functions.\u003c/p\u003e\n"],["\u003cp\u003eLibraries and scripts share certain resources like User Properties, while others, like Script Properties, are not shared and require explicit functions for access.\u003c/p\u003e\n"]]],[],null,["A library is a script project whose functions can be reused in other scripts.\n| **Warning:** A script that uses a library [doesn't run as quickly](/apps-script/guides/support/best-practices#avoid_libraries_in_ui-heavy_scripts) as it would if all the code were contained within a single script project. Although libraries can make development and maintenance more convenient, use them sparingly in projects where speed is critical. Because of this issue, library use should be limited in [add-ons](/workspace/add-ons/overview).\n\nGain access to a library\n\nTo include a library in your project you must have at least view-level\naccess to it. If you aren't the author of the library that you want to\ninclude, contact the author and request access.\n\nYou need the script ID of the library you want to include. When you have\naccess to the library, you can find the script ID on the **Project Settings**\nsettings page.\n\nAdd a library to your script project\n\n1. At the left of the Apps Script editor, next to \"Libraries,\" click Add a library add.\n2. In the \"Script ID\" field, paste in the script ID of the library.\n3. Click **Look up** . If you encounter an error, make sure that you have at least view-level access to the project that you're trying to include.\n4. Click the **Version** dropdown and select the version of the library to use.\n5. Check to see if the default \"Identifier\" name is the one that you want to use with this library. This is the name that your script uses to refer to the library. For example, if you set it to `Test` then you can call a method of that library as follows: `Test.libraryMethod()`. If you use an identifier name that matches the name of an already existing service, such as [`MailApp`](/apps-script/reference/mail/mail-app), or a previously added library, then the library you have added most recently overrides the existing service or library.\n6. Click **Add**.\n\nUse a library\n\nUse your included library as you would use a default service. For\nexample, if `Test` is the identifier for your library, type\n`Test` immediately followed by a period to see the list of methods in the library.\n\nThe reference documentation for an included library can be opened by following\nthese steps:\n\nAt the left of the script editor, next to the library name, click More\nmore_vert **\\\u003e Open in a new tab**.\n\nRemove a library\n\nAt the left of the script editor, next to the library name, click More\nmore_vert **\\\u003e Remove \\\u003e Remove library**.\n| If a library is deleted by the author you still need to remove it from your list of included libraries.\n\nUpdate a library\n\nYou can change the version of the library or update its identifier.\n\n1. At the left of the editor, under \"Libraries,\" click the name of the library.\n2. Make your changes and click **Save**.\n\nCreate and share a library\n\nTo use and share your script project as a library, follow the below steps.\n\n1. [Create a versioned deployment](/apps-script/guides/versions) of your script.\n2. Share at least view-level access with all potential users of the library.\n3. Give those users the script ID, which can be found on the **Project\n settings** settings page.\n\nBest practices\n\nHere are some guidelines to follow when writing a library:\n\n1. Choose a meaningful name for your project since it's used as the default identifier when your library is included by others.\n2. If you want one or more methods of your script to not be visible (nor usable) to your library users, you can end the name of the method with an underscore. For example, `myPrivateMethod_()`.\n3. Only enumerable global properties are visible to library users. This includes function declarations, variables created outside a function with `var`, and properties explicitly set on the global object. For example, `Object.defineProperty()` with `enumerable` set to `false` creates a symbol you can use in your library, but this symbol isn't accessible by your users.\n4. If you want your library users to make use of the script editor autocomplete and\n the automatically generated documentation, you must have JSDoc-style\n documentation for all your functions. Here's an example:\n\n /**\n * Raises a number to the given power, and returns the result.\n *\n * @param {number} base the number we're raising to a power\n * @param {number} exp the exponent we're raising the base to\n * @return {number} the result of the exponential calculation\n */\n function power(base, exp) { ... }\n\nResource scoping\n\nThere are two types of resources when you are working with libraries: shared\nand not-shared. A shared resource means that both the library and the including\nscript have a built-in access to the same instance of the resource. The\nfollowing diagram illustrates a shared resource using the example of\nUser Properties:\n\nA not-shared resource means that both library and the including script have\nbuilt-in access only to their instance of the resource. However, a library can\nprovide access to its not-shared resources by having explicit functions that\noperate on them. Here is an example of a function that you would include in\nyour library to expose its Script Properties: \n\n function getLibraryProperty(key) {\n const scriptProperties = PropertiesService.getScriptProperties();\n return scriptProperties.getProperty(key);\n }\n\nThe following diagram illustrates a not-shared resource using the example of\nScript Properties:\n\nThis table lists the shared and not-shared resources for your reference:\n\n| Resource | Shared\\* | Not-Shared\\*\\* | Notes |\n|------------------------------------|----------|----------------|------------------------------------------------------------------------------------|\n| Lock | | | The same instance is visible to all including scripts when created in the library. |\n| Script Properties | | | The same instance is visible to all including scripts when created in the library. |\n| Cache | | | The same instance is visible to all including scripts when created in the library. |\n| Triggers | | | Simple triggers created in library are not triggered by the including script. |\n| ScriptApp | | | |\n| UiApp | | | |\n| User Properties | | | |\n| Logger and execution transcript | | | |\n| Sites, Sheets and other containers | | | A call to `getActive()` returns the container of the including script. |\n| MailApp and GmailApp | | | |\n\nTest a library\n\nTo test your library, use the head deployment. Anyone who has editor-level\naccess to the script can use the head deployment.\n| You still need at least one version of the library saved.\n\nDebug a library\n\nWhen you use the debugger in a project that includes a library you\ncan step into a function of the included library. The code shows up in\nthe debugger in view-only mode and at the right version."]]